PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/colloquium.php

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