PageRenderTime 65ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/middCalendar/OLDevents1.php

https://github.com/gkipkorir/public_html
PHP | 307 lines | 258 code | 30 blank | 19 comment | 6 complexity | 036868a33aac388ddbe5efd727382ea8 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. echo "<div id='links'>";
  56. echo "</br>";
  57. //if session user is set (from logging in), show link to create event and log out
  58. if(isset($_SESSION['User'])){
  59. echo "Welcome ".$_SESSION['User']."</br>";
  60. echo "<a href='./CreateEvent.php'>Create Event</a></br>";
  61. echo "<a href='./CreateOrganization.php'>Create Organization</a></br>";
  62. echo "<a href='./addMembers.php'>Add Members to Org</a></br>";
  63. $sql2="SELECT supervisor FROM Users WHERE uid = '$_SESSION[uid]'";
  64. if (!mysqli_query($con,$sql2))
  65. {
  66. die('Error: ' . mysqli_error());
  67. }
  68. else
  69. {
  70. //execute the SQL query
  71. $result2 = mysqli_query($con,$sql2);
  72. }
  73. $row = mysqli_fetch_array($result2);
  74. if($row['supervisor']==1){
  75. echo "<a href='./approveEvents.php'>Approve Events</a></br>";
  76. }
  77. echo "<a href='./logout.php'>Don't forget to logout</a><br>";
  78. }
  79. else{ //if session user is not set, show link to log in and to create user
  80. $_SESSION['User'] = null;
  81. echo "<a href='./login.php'>Log In</a></br>";
  82. echo "<a href='./CreateUser.php'>Create User</a></br>";
  83. }
  84. //link to search page
  85. ?>
  86. <html>
  87. <body>
  88. <SCRIPT LANGUAGE="javascript">
  89. function toggle() {
  90. }
  91. </SCRIPT>
  92. <form action="insert1.php" method="post">
  93. <label for="midd_search_query">Search</label>
  94. <input type="search" id="midd_search_query" class="search_query x-webkit-speech" name="Search" placeholder="Search Calendar" x-webkit-speech required>
  95. <input type="submit" value="Go">
  96. <!--<input type="hidden" id="midd_ajax_search_url" value="/go/search">-->
  97. </form>
  98. <!--This creates the insert boxes
  99. <form action="insert1.php" method="post">
  100. Search: <input type="text" name="Search" /> <br> <br>
  101. <input type="submit" value="Search"/> <br> <br>
  102. </form>-->
  103. <!--This creates the drop down list-->
  104. <form name="thisForm" method="POST" action="query.php">
  105. <p>Select Genre: <select size="1" name="my_dropdown">
  106. <option value="Dance"> Dance </option>
  107. <option value="Party"> Party </option>
  108. <option value="Clam Bake"> Clam Bake </option>
  109. <option value="Pineapple"> Pineapple </option>
  110. <!--<option value="drinking"> drinking </option>-->
  111. <option value="sports"> sports </option>
  112. <input type="button" value="Go" name="btm_submit" onclick="validate()">
  113. </select></p>
  114. <p>
  115. </p>
  116. </form>
  117. </body>
  118. </html>
  119. <?php
  120. echo "</div>";
  121. $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday','Friday', 'Saturday');
  122. $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');
  123. echo "</br>";
  124. echo "<div id='content'>";
  125. echo "<div id='table1'>";
  126. echo "<table>";
  127. echo "<tr>";
  128. foreach($byDate as $key => $value)
  129. {
  130. echo "</br>";
  131. //echo "<td>";
  132. echo "<div class = 'date'>";
  133. echo "<a href='./date.php?date=".$key."' >";
  134. echo $days[date( "w", strtotime($key))]."</br>";
  135. echo $months[date( "m", strtotime($key))]." ".date( "d", strtotime($key))."</br></br>";
  136. echo "</a></div>";
  137. //array shift removes first value of array, which kept being current time for some reason.
  138. array_shift($value);
  139. //print out each event that occurs on day, as a link to more details
  140. foreach($value as $event){
  141. echo "<a href='./eventInfo.php?eid=".$event['eid']."'>".$event['name']."</a> ".date('g:i A',strtotime($event['time']));
  142. //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>";
  143. echo "<div class = 'description'>".substr($event['description'],0,35)."...</div>";
  144. }
  145. //echo "</td>";
  146. }
  147. echo "</tr>";
  148. echo "</table>";
  149. echo "</div>";
  150. echo "</div>";
  151. //Display events
  152. //echo "</br>Events in the Next 7 days: </br>";
  153. //while ($row = mysqli_fetch_array($result)) {
  154. //for each event, display its name as a link to detailed event info, with eid in the url
  155. // echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
  156. //}
  157. //view session data:
  158. //print_r($_SESSION);
  159. //close connection
  160. mysql_close($con)
  161. ?>
  162. <style>
  163. html{
  164. background: #737373;
  165. background-image:url('./1003background1.png');
  166. background-attachment: fixed;
  167. }
  168. a:visited, a:link{
  169. color:#0066CC;
  170. }
  171. #links{
  172. border-radius: 25px;
  173. color: pink;
  174. position:fixed;
  175. background-color:black;
  176. opacity: .90;
  177. width:10%;
  178. padding-top: 20px;
  179. padding-bottom: 20px;
  180. padding-right: 10%;
  181. padding-left: 10%;
  182. border-width: 3px;
  183. border-color: black;
  184. margin-top: 10%;
  185. margin-right: 20%;
  186. margin-left: 65%;
  187. z-index: 1;
  188. //float:top;
  189. //width: 200px ;
  190. //background: white;
  191. //opacity:0.9;
  192. }
  193. #content{
  194. float:left;
  195. }
  196. #table1{
  197. border-radius: 25px;
  198. opacity: .9;
  199. color: pink;
  200. background-color: black;
  201. width: 1100px ;
  202. margin-left: auto ;
  203. margin-right: auto ;
  204. text-align:center;
  205. font-size: 28;
  206. }
  207. div.date a:link,div.date a:visited{
  208. text-transform:uppercase;
  209. font-weight:bold;
  210. color:white;
  211. font-size:35;
  212. }
  213. .description{
  214. color: #585858;
  215. font-size:22;
  216. }
  217. tr{
  218. text-align:center;
  219. }
  220. table, th, td
  221. {
  222. font-size:20;
  223. border: 1px solid black;
  224. text-align:center;
  225. }
  226. td{
  227. vertical-align:top;
  228. width:200;
  229. }
  230. </style>
  231. <!DOCTYPE HTML>
  232. <html>
  233. <title> Midd Events </title>
  234. <body>
  235. </body>
  236. </html>