PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/xy.php

https://github.com/xmarcosx/enroll
PHP | 446 lines | 414 code | 2 blank | 30 comment | 67 complexity | aecd2c35338d4a9fbf1955c6a8aadb48 MD5 | raw file
  1. <!DOCTYPE html>
  2. <?php
  3. session_start();
  4. //Credentials aren't legit or user isn't an admin, kick back to login screen
  5. if (!isset($_SESSION['username'])){
  6. $loggedin=false;
  7. $username=NULL;
  8. }
  9. else{
  10. $loggedin=true;
  11. $master_username=$_SESSION['username'];
  12. $ghostuser=$_SESSION['ghostuser'];
  13. if(!is_null($ghostuser))
  14. $username=$_SESSION['ghostuser'];
  15. else
  16. $username=$_SESSION['username'];
  17. }
  18. include_once 'admin/settings.php';
  19. //Connects to MySQL and Selects Database
  20. $con = mysql_connect($host,$db_username,$db_password);
  21. if (!$con)
  22. die('Could not connect: ' . mysql_error());
  23. //Select DB
  24. mysql_select_db($db, $con);
  25. //Get class levels
  26. $get_settings_result=mysql_query(
  27. "SELECT freshman,sophomore,junior,senior,
  28. xy_num_days_open,xy_time_open,xy_num_days_close,xy_time_close
  29. FROM settings
  30. LIMIT 1") or die(mysql_error());
  31. $get_settings_array=mysql_fetch_array($get_settings_result);
  32. $freshman=$get_settings_array['freshman'];
  33. $sophomore=$get_settings_array['sophomore'];
  34. $junior=$get_settings_array['junior'];
  35. $senior=$get_settings_array['senior'];
  36. //Get user's class level
  37. $class_level=null;
  38. $get_graduation_year_result=mysql_query(
  39. "SELECT graduation_year FROM users WHERE username='$username' LIMIT 1") or die(mysql_error());
  40. if (mysql_num_rows($get_graduation_year_result) > 0){
  41. $get_graduation_year_array=mysql_fetch_array($get_graduation_year_result);
  42. $graduation_year=$get_graduation_year_array['graduation_year'];
  43. if($graduation_year==$freshman)
  44. $class_level="freshman";
  45. elseif($graduation_year==$sophomore)
  46. $class_level="sophomore";
  47. elseif($graduation_year==$junior)
  48. $class_level="junior";
  49. elseif($graduation_year==$senior)
  50. $class_level="senior";
  51. }
  52. //Get next date for XY Courses
  53. $next_xy_result=mysql_query("SELECT id,date
  54. FROM course_schedule
  55. WHERE date >= " . date('Y-m-d') . " AND (x=1 OR y=1)
  56. ORDER BY date LIMIT 1") or die(mysql_error());
  57. if (mysql_num_rows($next_xy_result)==1){
  58. $next_xy_row=mysql_fetch_array($next_xy_result);
  59. $next_xy=$next_xy_row['date'];
  60. $next_xy_id=$next_xy_row['id'];
  61. //Grab all of the teacher's xy options for that date
  62. $result = mysql_query("SELECT users.lastname, users.firstname, assignments.id AS xyassnid,
  63. courses.name, courses.description, courses.image, assignments.xy_block AS block, assignments.class_size,
  64. courses.freshmen,courses.sophomores,courses.juniors,courses.seniors
  65. FROM `users`
  66. INNER JOIN `courses` on courses.teacher_id = users.id
  67. INNER JOIN `assignments` on assignments.course_id = courses.id
  68. WHERE assignments.final=1 AND assignments.xy_date_id=$next_xy_id AND courses.type='xy' ") or die(mysql_error());
  69. $chosen_xy_name=NULL;
  70. $chosen_xy_image=NULL;
  71. $chosen_xy_id=NULL;
  72. $chosen_xy_room=NULL;
  73. $chosen_x_name=NULL;
  74. $chosen_x_image=NULL;
  75. $chosen_x_id=NULL;
  76. $chosen_x_room=NULL;
  77. $chosen_y_name=NULL;
  78. $chosen_y_image=NULL;
  79. $chosen_y_id=NULL;
  80. $chosen_y_room=NULL;
  81. //If user is logged in
  82. if(isset($_SESSION['username'])){
  83. $chosen_xy_result=mysql_query("SELECT users.username, courses.name, courses.image, assignments.xy_block AS block, assignments.id, assignments.room
  84. FROM `users`
  85. INNER JOIN `enrollments` on enrollments.users_id=users.id
  86. INNER JOIN `assignments` on assignments.id=enrollments.assignments_id
  87. INNER JOIN `courses` on assignments.course_id = courses.id
  88. WHERE users.username='$username' AND assignments.xy_date_id=$next_xy_id ") or die(mysql_error());
  89. while($chosen_xy_row=mysql_fetch_array($chosen_xy_result)){
  90. if(strcmp($chosen_xy_row['block'],"xy") == 0){
  91. $chosen_xy_name=$chosen_xy_row['name'];
  92. $chosen_xy_image=$chosen_xy_row['image'];
  93. $chosen_xy_id=$chosen_xy_row['id'];
  94. $chosen_xy_room=$chosen_xy_row['room'];
  95. }
  96. elseif(strcmp($chosen_xy_row['block'],"x") == 0){
  97. $chosen_x_name=$chosen_xy_row['name'];
  98. $chosen_x_image=$chosen_xy_row['image'];
  99. $chosen_x_id=$chosen_xy_row['id'];
  100. $chosen_x_room=$chosen_xy_row['room'];
  101. }
  102. else{
  103. $chosen_y_name=$chosen_xy_row['name'];
  104. $chosen_y_image=$chosen_xy_row['image'];
  105. $chosen_y_id=$chosen_xy_row['id'];
  106. $chosen_y_room=$chosen_xy_row['room'];
  107. }
  108. }
  109. }
  110. }
  111. $xy_registration_open=false;
  112. if(isset($next_xy)){
  113. $xy_open=strtotime($next_xy) - ($get_settings_array['xy_num_days_open'] * 86400 + strtotime( $get_settings_array['xy_time_open']));
  114. $xy_close=strtotime(date("Y-m-d", strtotime($next_xy) - $get_settings_array['xy_num_days_close'] * 86400) + $get_settings_array['xy_time_close'] );
  115. if(time() >= $xy_open && time() < $xy_close)
  116. $xy_registration_open=true;
  117. }
  118. $status=$_GET['status'];
  119. ?>
  120. <html lang="en">
  121. <head>
  122. <meta charset="utf-8">
  123. <title>Enroll: <?php echo $school_name; ?></title>
  124. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  125. <meta name="description" content="Flexible Scheduling for Today's Classroom">
  126. <meta name="author" content="Marcos Alcozer">
  127. <meta name="keywords" content="Education, Scheduling">
  128. <!-- Le styles -->
  129. <style>
  130. body {
  131. padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
  132. }
  133. </style>
  134. <link href="css/wookmark.css" rel="stylesheet">
  135. <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
  136. <link href="css/admin.css" rel="stylesheet">
  137. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  138. <!--[if lt IE 9]>
  139. <script src="../js/html5shiv.js"></script>
  140. <![endif]-->
  141. </head>
  142. <body>
  143. <?php include_once("admin/analyticstracking.php") ?>
  144. <div class="navbar navbar-inverse navbar-fixed-top">
  145. <div class="navbar-inner">
  146. <div class="container">
  147. <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
  148. <span class="icon-bar"></span>
  149. <span class="icon-bar"></span>
  150. <span class="icon-bar"></span>
  151. </button>
  152. <a class="brand appname" href="#">Enroll<img src='img/beta-icon.png' style="vertical-align:text-top;"/></a>
  153. <div class="nav-collapse collapse">
  154. <ul class="nav">
  155. <li class="active"><a href="xy.php">XY</a></li>
  156. <li><a href="colloquium.php">Colloquium</a></li>
  157. </ul>
  158. <ul class="nav pull-right">
  159. <?php if(!is_null($ghostuser)){ ?>
  160. <li><a href="javascript:void(0)" onclick='ghost_user("<?php echo $master_username; ?>","admin");'><?php echo $master_username; ?></a></li>
  161. <?php
  162. }
  163. if(!$loggedin)
  164. echo "<li class='login-button'><a href='login.html' style='color:#FFFFFF'>Login</a></li>";
  165. else
  166. echo "<li class='login-button'><a href='logout.php' style='color:#FFFFFF'>Logout</a></li>";
  167. ?>
  168. </ul>
  169. </div><!--/.nav-collapse -->
  170. </div>
  171. </div>
  172. <?php if(!$status && !is_null($status)) { ?>
  173. <div id="failed" class="alert alert-error text-center">
  174. <button type="button" class="close" data-dismiss="alert">&times;</button>
  175. Something went terribly wrong, please try again.
  176. </div>
  177. <?php }else if($status==1 && !is_null($status)) { ?>
  178. <div id="success" class="alert alert-success text-center">
  179. <button type="button" class="close" data-dismiss="alert">&times;</button>
  180. You got it! Congrats!
  181. </div>
  182. <?php }else if($status==3 && !is_null($status)) { ?>
  183. <div id="success" class="alert alert-info text-center">
  184. <button type="button" class="close" data-dismiss="alert">&times;</button>
  185. Oh no, so sorry, but that one has just filled up. Please select another.
  186. </div>
  187. <?php } ?>
  188. </div>
  189. <div class="container">
  190. <?php
  191. if(isset($next_xy)){
  192. echo "<h1>XY for " . date('l F jS, Y', strtotime($next_xy)) . "</h1>";
  193. }
  194. else{
  195. echo "<h1>No XY dates are currently set.</h1>";
  196. }
  197. ?>
  198. <hr />
  199. <!-- SHOW AGENDA IS USER IS LOGGED IN AND HAS ALREADY CHOSEN A X OR Y COURSE -->
  200. <?php if(isset($_SESSION['username']) &&
  201. (!is_null($chosen_xy_name) ||
  202. !is_null($chosen_x_name) ||
  203. !is_null($chosen_y_name)))
  204. { ?>
  205. <div class="row" style="min-height: 450px;">
  206. <h2>Agenda</h2>
  207. <ul id="tiles">
  208. <!-- IF USER HAS ALREADY CHOSEN AN XY -->
  209. <?php
  210. if(isset($chosen_xy_name))
  211. { ?>
  212. <div id="tile<?php echo $chosen_xy_id; ?>">
  213. <form id='remove<?php echo $chosen_xy_id; ?>' >
  214. <input name='type' type='hidden' value='xy' />
  215. <input name='courseid' type='hidden' value='<?php echo $chosen_xy_id; ?>' />
  216. <input name='username' type='hidden' value='<?php echo $username; ?>' />
  217. </form>
  218. <li>
  219. <?php if(isset($username) && $xy_registration_open){ ?>
  220. <i id="<?php echo $chosen_xy_id; ?>" class="icon-remove-sign remove_assignment"></i>
  221. <?php } ?>
  222. <img class="img-rounded" src="img/courses/<?php echo $chosen_xy_image; ?>" width="200" />
  223. <p><?php echo $chosen_xy_name; ?></p>
  224. <p>Room <?php echo $chosen_xy_room; ?></p>
  225. <p>Spans both X and Y blocks.</p>
  226. </li>
  227. </div>
  228. <?php }
  229. //IF USER HAS ALREADY CHOSEN AN X
  230. if(isset($chosen_x_name))
  231. { ?>
  232. <div id="tile<?php echo $chosen_x_id; ?>">
  233. <form id='remove<?php echo $chosen_x_id; ?>' >
  234. <input name='type' type='hidden' value='xy' />
  235. <input name='courseid' type='hidden' value='<?php echo $chosen_x_id; ?>' />
  236. <input name='username' type='hidden' value='<?php echo $username; ?>' />
  237. </form>
  238. <li>
  239. <?php if(isset($username) && $xy_registration_open){ ?>
  240. <i id="<?php echo $chosen_x_id; ?>" class="icon-remove-sign remove_assignment"></i>
  241. <?php } ?>
  242. <img class="img-rounded" src="img/courses/<?php echo $chosen_x_image; ?>" width="200" />
  243. <p><?php echo $chosen_x_name; ?></p>
  244. <p>Room <?php echo $chosen_x_room; ?></p>
  245. <p>X Block</p>
  246. </li>
  247. </div>
  248. <?php }
  249. //IF USER HAS ALREADY CHOSEN AN X
  250. if(isset($chosen_y_name))
  251. { ?>
  252. <div id="tile<?php echo $chosen_y_id; ?>">
  253. <form id='remove<?php echo $chosen_y_id; ?>' >
  254. <input name='type' type='hidden' value='xy' />
  255. <input name='courseid' type='hidden' value='<?php echo $chosen_y_id; ?>' />
  256. <input name='username' type='hidden' value='<?php echo $username; ?>' />
  257. </form>
  258. <li>
  259. <?php if(isset($username) && $xy_registration_open){ ?>
  260. <i id="<?php echo $chosen_y_id; ?>" class="icon-remove-sign remove_assignment"></i>
  261. <?php } ?>
  262. <img class="img-rounded" src="img/courses/<?php echo $chosen_y_image; ?>" width="200" />
  263. <p><?php echo $chosen_y_name; ?></p>
  264. <p>Room <?php echo $chosen_y_room; ?></p>
  265. <p>Y Block</p>
  266. </li>
  267. </div>
  268. <?php } ?>
  269. </ul>
  270. </div>
  271. <?php } ?>
  272. <!-- XY CHOICES -->
  273. <div id='choices' class='row'>
  274. <?php
  275. if((is_null($chosen_xy_name) && is_null($chosen_x_name) && is_null($chosen_y_name)) ||
  276. (is_null($chosen_xy_name) && is_null($chosen_y_name)) ||
  277. (is_null($chosen_xy_name) && is_null($chosen_x_name)))
  278. {
  279. ?>
  280. <!-- FILTER BETWEEN X AND Y COURSES-->
  281. <?php if(is_null($chosen_x_name) &&
  282. is_null($chosen_y_name))
  283. { ?>
  284. <ul id="filters" >
  285. <div><li data-filter="x"><h2>X Period</h2></li></div>
  286. <div><li data-filter="y"><h2>Y Period</h2></li></div>
  287. </ul>
  288. <?php } ?>
  289. <ul id="tiles">
  290. <?php
  291. while($row = mysql_fetch_array($result)){
  292. if(($row['freshmen'] && strcmp($class_level,'freshman')==0) ||
  293. ($row['sophomore'] && strcmp($class_level,'sophomore')==0) ||
  294. ($row['junior'] && strcmp($class_level,'junior')==0) ||
  295. ($row['senior'] && strcmp($class_level,'senior')==0 ||
  296. !$loggedin))
  297. {
  298. $xyassnid = $row['xyassnid'];
  299. $image = $row['image'];
  300. $name = $row['name'];
  301. $description = $row['description'];
  302. $lastname = $row['lastname'];
  303. $firstname = $row['firstname'];
  304. $block = $row['block'];
  305. $class_size = $row['class_size'];
  306. if(isset($_SESSION['username'])) {
  307. $spots_left_result=mysql_query("SELECT COUNT(*) AS count FROM `enrollments` WHERE assignments_id=$xyassnid") or die(mysql_error());
  308. $spots_left=0;
  309. if (mysql_num_rows($spots_left_result) > 0){
  310. $spots_left_array=mysql_fetch_array($spots_left_result);
  311. $spots_left=$class_size - $spots_left_array['count'];
  312. }
  313. }
  314. if(($spots_left > 0 || is_null($spots_left)) &&
  315. ((is_null($chosen_x_name) && strcmp($block, "x") == 0 && is_null($chosen_xy_name)) ||
  316. (is_null($chosen_y_name) && strcmp($block, "y") == 0 && is_null($chosen_xy_name)) ||
  317. (is_null($chosen_y_name) && is_null($chosen_x_name) && strcmp($block, "xy") == 0)) )
  318. {
  319. ?>
  320. <li class="<?php if(strcmp($block, 'xy')==0){echo 'x y';}else{echo $block;} ?> card" value="<?php echo $xyassnid; ?>" >
  321. <form action='enroll.php' method='post' >
  322. <input name='type' type='hidden' value='xy' />
  323. <input name='courseid' type='hidden' value='<?php echo $xyassnid; ?>' />
  324. <input name='username' type='hidden' value='<?php echo $username; ?>' />
  325. <input name='class_size' type='hidden' value='<?php echo $class_size; ?>' />
  326. <img class="img-rounded card-image" src="img/courses/<?php echo $image; ?>" width="200" id='<?php echo $cassnid; ?>' />
  327. <p><?php echo $name; ?></p>
  328. <p><?php echo $firstname . " " . $lastname; ?></p>
  329. <?php
  330. if(strcmp($block, 'xy')==0){
  331. echo "<p>Spans both X and Y blocks.</p>";
  332. }
  333. else{
  334. echo "<p>" . strtoupper($block) . " Block</p>";
  335. }
  336. ?>
  337. <?php
  338. if(isset($_SESSION['username'])) {
  339. echo "<p>$spots_left Spots Left</p>";
  340. } ?>
  341. <p class="desc" id='<?php echo $xyassnid; ?>'>
  342. <?php echo substr($description, 0, 200); ?><span id="ellipses<?php echo $xyassnid; ?>">...</span><span id="description<?php echo $xyassnid; ?>" style="display: none;"><?php echo substr($description, 200); ?></span>
  343. </p>
  344. <div id='status<?php echo $xyassnid; ?>'></div>
  345. <?php
  346. if(isset($username) && $xy_registration_open)
  347. echo "<p><button class='btn btn-primary' type='submit' >Enroll</button></p>";
  348. ?>
  349. </form>
  350. </li>
  351. <?php
  352. }
  353. }
  354. }
  355. mysql_close();
  356. ?>
  357. </ul>
  358. <?php } ?>
  359. </div>
  360. </div>
  361. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  362. <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
  363. <!-- <script src="js/bootstrap.min.js"></script> -->
  364. <script src="js/jquery.wookmark.min.js"></script>
  365. <script src="js/student.js"></script>
  366. <!-- Once the images are loaded, initalize the Wookmark plug-in. -->
  367. <script type="text/javascript">
  368. $(document).ready(new function() {
  369. // This filter is later used as the selector for which grid items to show.
  370. var filter = '', handler;
  371. // Prepare layout options.
  372. var options = {
  373. align: 'left',
  374. autoResize: true, // This will auto-update the layout when the browser window is resized.
  375. container: $('#choices'), // Optional, used for some extra CSS styling
  376. offset: 15, // Optional, the distance between grid items
  377. itemWidth: 210 // Optional, the width of a grid item
  378. };
  379. // This function filters the grid when a change is made.
  380. var refresh = function() {
  381. // This hides all grid items ("inactive" is a CSS class that sets opacity to 0).
  382. $('#tiles li').addClass('inactive');
  383. // Create a new layout selector with our filter.
  384. handler = $(filter);
  385. // This shows the items we want visible.
  386. handler.removeClass("inactive");
  387. // This updates the layout.
  388. handler.wookmark(options);
  389. }
  390. /**
  391. * This function checks all filter options to see which ones are active.
  392. * If they have changed, it also calls a refresh (see above).
  393. */
  394. var updateFilters = function() {
  395. var oldFilter = filter,
  396. filters = [];
  397. // Collect filter list.
  398. var items = $('#filters li'),
  399. i = 0, length = items.length, item;
  400. for(; i < length; i++) {
  401. item = items.eq(i);
  402. if(item.hasClass('active')) {
  403. filters.push('#tiles li.' + item.attr('data-filter'));
  404. }
  405. }
  406. // If no filters active, set default to show all.
  407. if (filters.length == 0) {
  408. filters.push('#tiles li');
  409. }
  410. // Finalize our filter selector for jQuery.
  411. filter = filters.join(', ');
  412. // If the filter has changed, update the layout.
  413. if(oldFilter != filter) {
  414. refresh();
  415. }
  416. };
  417. /**
  418. * When a filter is clicked, toggle it's active state and refresh.
  419. */
  420. var onClickFilter = function(event) {
  421. $('#filters li').removeClass('active');
  422. $(event.currentTarget).toggleClass('active');
  423. updateFilters();
  424. }
  425. // Capture filter click events.
  426. $('#filters li').click(onClickFilter);
  427. // Do initial update (shows all items).
  428. updateFilters();
  429. $(".desc").click(function(event){
  430. $("#ellipses" + event.target.id).toggle();
  431. $("#description" + event.target.id).toggle();
  432. refresh();
  433. });
  434. $(".card-image").click(function(event){
  435. $("#ellipses" + event.target.id).toggle();
  436. $("#description" + event.target.id).toggle();
  437. refresh();
  438. });
  439. </script>
  440. </body>
  441. </html>