PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/middCalendar/events1.php~

https://github.com/gkipkorir/public_html
Unknown | 314 lines | 240 code | 74 blank | 0 comment | 0 complexity | 001fb48d952b15225b83d8d466a38f48 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 validate() {
  90. fm = document.thisForm
  91. //use validation here to make sure the user entered
  92. //the information correctly
  93. fm.submit()
  94. }
  95. </SCRIPT>
  96. <form action="insert1.php" method="post">
  97. <label for="midd_search_query">Search</label>
  98. <input type="search" id="midd_search_query" class="search_query x-webkit-speech" name="Search" placeholder="Search Calendar" x-webkit-speech required>
  99. <input type="submit" value="Go">
  100. <!--<input type="hidden" id="midd_ajax_search_url" value="/go/search">-->
  101. </form>
  102. <!--This creates the insert boxes
  103. <form action="insert1.php" method="post">
  104. Search: <input type="text" name="Search" /> <br> <br>
  105. <input type="submit" value="Search"/> <br> <br>
  106. </form>-->
  107. <!--This creates the drop down list-->
  108. <form name="thisForm" method="POST" action="query.php">
  109. <p>Select Genre: <select size="1" name="my_dropdown">
  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="button" value="Go" name="btm_submit" onclick="validate()">
  117. </select></p>
  118. <p>
  119. </p>
  120. </form>
  121. </body>
  122. </html>
  123. <?php
  124. echo "</div>";
  125. $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday','Friday', 'Saturday');
  126. $months = array('01'=>'January', 'February', 'March', 'April','May','June', 'July', 'August', 'September', 'October', 'November', 'December');
  127. echo "</br>";
  128. echo "<div id='content'>";
  129. echo "<div id='table1'>";
  130. echo "<table>";
  131. echo "<tr>";
  132. foreach($byDate as $key => $value)
  133. {
  134. echo "</br>";
  135. //echo "<td>";
  136. echo "<div class = 'date'>";
  137. echo "<a href='./date.php?date=".$key."' >";
  138. echo $days[date( "w", strtotime($key))]."</br>";
  139. echo $months[date( "m", strtotime($key))]." ".date( "d", strtotime($key))."</br></br>";
  140. echo "</a></div>";
  141. //array shift removes first value of array, which kept being current time for some reason.
  142. array_shift($value);
  143. //print out each event that occurs on day, as a link to more details
  144. foreach($value as $event){
  145. echo "<a href='./eventInfo.php?eid=".$event['eid']."'>".$event['name']."</a> ".date('g:i A',strtotime($event['time']));
  146. //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>";
  147. echo "<div class = 'description'>".substr($event['description'],0,15)."...</div>";
  148. }
  149. //echo "</td>";
  150. }
  151. echo "</tr>";
  152. echo "</table>";
  153. echo "</div>";
  154. echo "</div>";
  155. //Display events
  156. //echo "</br>Events in the Next 7 days: </br>";
  157. //while ($row = mysqli_fetch_array($result)) {
  158. //for each event, display its name as a link to detailed event info, with eid in the url
  159. // echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
  160. //}
  161. //view session data:
  162. //print_r($_SESSION);
  163. //close connection
  164. mysql_close($con)
  165. ?>
  166. <style>
  167. html{
  168. background: #737373;
  169. background-image:url('./1003background1.png');
  170. background-attachment: fixed;
  171. }
  172. a:visited, a:link{
  173. color:#0066CC;
  174. }
  175. #links{
  176. border-radius: 25px;
  177. color: pink;
  178. position:fixed;
  179. background-color:black;
  180. opacity: .90;
  181. width:10%;
  182. padding-top: 20px;
  183. padding-bottom: 20px;
  184. padding-right: 10%;
  185. padding-left: 10%;
  186. border-width: 3px;
  187. border-color: black;
  188. margin-top: 10%;
  189. margin-right: 20%;
  190. margin-left: 65%;
  191. z-index: 1;
  192. //float:left;
  193. //width: 200px ;
  194. //background: white;
  195. //opacity:0.9;
  196. }
  197. #content{
  198. float:left;
  199. }
  200. #table1{
  201. border-radius: 25px;
  202. opacity: .9;
  203. color: pink;
  204. background-color: black;
  205. width: 1100px ;
  206. margin-left: auto ;
  207. margin-right: auto ;
  208. text-align:center;
  209. font-size: 28;
  210. }
  211. div.date a:link,div.date a:visited{
  212. text-transform:uppercase;
  213. font-weight:bold;
  214. color:white;
  215. font-size:35;
  216. }
  217. .description{
  218. color: #585858;
  219. font-size:24;
  220. }
  221. tr{
  222. text-align:center;
  223. }
  224. table, th, td
  225. {
  226. font-size:20;
  227. border: 1px solid black;
  228. text-align:center;
  229. }
  230. td{
  231. vertical-align:top;
  232. width:200;
  233. }
  234. </style>
  235. <!DOCTYPE HTML>
  236. <html>
  237. <title> Midd Events </title>
  238. <body>
  239. </body>
  240. </html>