PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/teacher/preenroll_xy.php

https://github.com/xmarcosx/enroll
PHP | 283 lines | 271 code | 0 blank | 12 comment | 13 complexity | 37108213a4aab98dd970456ee0d3fe57 MD5 | raw file
  1. <?php
  2. session_start();
  3. //Credentials aren't legit or user isn't an admin, kick back to login screen
  4. if (!isset($_SESSION['username']) ||
  5. $_SESSION['login']!=true ||
  6. $_SESSION['student']) {
  7. $_SESSION['from_teacher']=true;
  8. header("Location: ../login.html");
  9. }
  10. $master_username=$_SESSION['username'];
  11. $ghostuser=$_SESSION['ghostuser'];
  12. if(!is_null($ghostuser))
  13. $username=$_SESSION['ghostuser'];
  14. else
  15. $username=$_SESSION['username'];
  16. //Code to connect to database
  17. include_once '../admin/settings.php';
  18. //Connects to MySQL and Selects Database
  19. $con = mysql_connect($host,$db_username,$db_password);
  20. if (!$con)
  21. die('Could not connect: ' . mysql_error());
  22. //Select DB
  23. mysql_select_db($db, $con);
  24. //Internal user id
  25. $userid=NULL;
  26. $get_userid_result=mysql_query("SELECT id FROM users WHERE username=\"$username\"") or die(mysql_error());
  27. $get_userid_array=mysql_fetch_array($get_userid_result);
  28. $userid=$get_userid_array['id'];
  29. //Get next date XY is offered
  30. $next_date=null;
  31. $next_date_id=null;
  32. $next_xy_result=mysql_query(
  33. "SELECT *
  34. FROM course_schedule
  35. WHERE date >= " . date('Y-m-d') . " AND (x=1 OR y=1) ORDER BY date LIMIT 1");
  36. $next_xy_row= mysql_fetch_array($next_xy_result);
  37. $next_date=$next_xy_row['date'];
  38. $next_date_id=$next_xy_row['id'];
  39. //Get all XY assignments for teacher
  40. $dates_result=mysql_query(
  41. "SELECT assignments.id, courses.name, assignments.xy_date_id as date_id, course_schedule.date
  42. FROM assignments
  43. INNER JOIN `courses` on assignments.course_id=courses.id
  44. INNER JOIN `course_schedule` on assignments.xy_date_id=course_schedule.id
  45. WHERE courses.teacher_id=$userid AND assignments.final=1")
  46. or die(mysql_error());
  47. //Get Student List
  48. $students_result=mysql_query("SELECT id,firstname,lastname,username FROM users WHERE role='student'") or die(mysql_error());
  49. ?>
  50. <!DOCTYPE html>
  51. <html lang='en'>
  52. <head>
  53. <meta charset='utf-8'>
  54. <title>Enroll: <?php echo $school_name; ?></title>
  55. <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  56. <meta name='description' content="Flexible Scheduling for Today's Classroom">
  57. <meta name='author' content='Marcos Alcozer'>
  58. <meta name='keywords' content='Education, Scheduling'>
  59. <!-- CSS -->
  60. <style>
  61. body {
  62. padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
  63. }
  64. </style>
  65. <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
  66. <link href="../css/admin.css" rel="stylesheet">
  67. <!-- JQUERY -->
  68. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  69. <!-- BOOTSTRAP -->
  70. <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
  71. <!-- AJAX UPLOAD BY BRYAN GENTRY -->
  72. <!-- http://bryangentry.us/ajax-upload-with-javascript-and-php-upload-an-image-and-display-a-preview/ -->
  73. <script src="../js/ajaxupload.js"></script>
  74. <!-- FORM VALIDATION USING JQUERY -->
  75. <!-- http://alittlecode.com/jquery-form-validation-with-styles-from-twitter-bootstrap/ -->
  76. <!-- <script src="../js/jquery.validate.min.js"></script> -->
  77. <!-- <script src="../js/validate.js"></script> -->
  78. <!-- INHOUSE JAVASCRIPT -->
  79. <script src="../js/teacher.js"></script>
  80. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  81. <!--[if lt IE 9]>
  82. <script src="../js/html5shiv.js"></script>
  83. <![endif]-->
  84. </head>
  85. <body>
  86. <?php include_once("../admin/analyticstracking.php") ?>
  87. <div class="navbar navbar-inverse navbar-fixed-top">
  88. <div class="navbar-inner">
  89. <div class="container">
  90. <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
  91. <span class="icon-bar"></span>
  92. <span class="icon-bar"></span>
  93. <span class="icon-bar"></span>
  94. </button>
  95. <a class="brand appname" href="#">Enroll<img src='../img/beta-icon.png' style="vertical-align:text-top;"/></a>
  96. <div class="nav-collapse collapse">
  97. <ul class="nav">
  98. <li><a href="agenda.php">Agenda</a></li>
  99. <li class="dropdown active">
  100. <a href="#" class="dropdown-toggle" data-toggle="dropdown">X/Y <b class="caret"></b></a>
  101. <ul class="dropdown-menu">
  102. <li><a href="assigned_xy.php">Assign Course</a></li>
  103. <li><a href="repository_xy.php">Course Repository</a></li>
  104. <li><a href="preenroll_xy.php">Enroll Students</a></li>
  105. </ul>
  106. </li>
  107. <li class="dropdown">
  108. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Colloquium <b class="caret"></b></a>
  109. <ul class="dropdown-menu">
  110. <li><a href="assigned_col.php">Assign Course</a></li>
  111. <li><a href="repository_col.php">Course Repository</a></li>
  112. <li class="dropdown-submenu">
  113. <a tabindex="-1" href="#">Enroll Students</a>
  114. <ul class="dropdown-menu">
  115. <li><a href="preenroll_col.php?semester=1">Semester 1</a></li>
  116. <li><a href="preenroll_col.php?semester=2">Semester 2</a></li>
  117. </ul>
  118. </li>
  119. </ul>
  120. </li>
  121. </ul>
  122. <ul class="nav pull-right">
  123. <?php if($_SESSION['admin'] && $_SESSION['teacher']){
  124. echo "<li><a href='../admin'>Admin Panel</a></li>";
  125. }
  126. if(!is_null($ghostuser)){ ?>
  127. <li><a href="javascript:void(0)" onclick='ghost_user("<?php echo $master_username; ?>","admin");'><?php echo $master_username; ?></a></li>
  128. <?php
  129. }
  130. if(!isset($_SESSION['username']))
  131. echo "<li class='login-button'><a href='../login.html' style='color:#FFFFFF'>Login</a></li>";
  132. else
  133. echo "<li class='login-button'><a href='../logout.php' style='color:#FFFFFF'>Logout</a></li>";
  134. ?>
  135. </ul>
  136. </div><!--/.nav-collapse -->
  137. </div>
  138. </div>
  139. </div>
  140. <div class='container'>
  141. <?php
  142. //If status returned is 0
  143. if($_GET['status']==3){
  144. ?>
  145. <div class="alert alert-error fade in">
  146. <button type="button" class="close" data-dismiss="alert">&times;</button>
  147. Sorry, that student is already enrolled elsewhere.
  148. </div>
  149. <?php } ?>
  150. <div class="row">
  151. <div class="span3 bs-docs-sidebar hidden-phone hidden-tablet">
  152. <ul class="nav nav-list bs-docs-sidenav">
  153. <?php
  154. //Iterate through the dates and create side navigation menu
  155. while($row=mysql_fetch_array($dates_result)){
  156. echo "<li";
  157. if(strcmp($row['date'], $next_date)==0)
  158. echo " class='active' ";
  159. echo "><a href='#" . $row['id'] . "'><i class='icon-chevron-right'></i>" . date('D F jS, Y', strtotime($row['date'])) . "</a></li>";
  160. }
  161. ?>
  162. </ul>
  163. </div>
  164. <div class="span9">
  165. <?php
  166. if (mysql_num_rows($dates_result) == 0){
  167. echo "Looks like the programmer has not finalized your XY selection just yet. <p>You may not enroll a student until it has been finalized, check back soon.</p>";
  168. }
  169. //Iterate through the dates and create a section for each date that will house enrollment rosters
  170. mysql_data_seek($dates_result,0);
  171. while($date=mysql_fetch_array($dates_result)){
  172. $xyassid=$date['id'];
  173. //Get Current Roster for Course
  174. $xy_roster_result=mysql_query(
  175. "SELECT enrollments.id,enrollments.users_id,users.firstname,users.lastname
  176. FROM enrollments
  177. INNER JOIN `users` on enrollments.users_id=users.id
  178. WHERE enrollments.assignments_id=$xyassid") or die(mysql_error());
  179. ?>
  180. <div class='page-header'>
  181. <h1><?php echo $date['name']; ?></h1>
  182. </div>
  183. <section id="<?php echo $xyassid; ?>">
  184. <div class="row">
  185. <!-- Current Roster for Course -->
  186. <div class='span4'>
  187. <h3>Current Roster</h3>
  188. <table class="table table-striped table-hover table-condensed">
  189. <thead>
  190. <tr>
  191. <th>Last Name</th>
  192. <th>First Name</th>
  193. <th>Username</th>
  194. <th></th>
  195. </tr>
  196. </thead>
  197. <tbody>
  198. <?php
  199. if (mysql_num_rows($xy_roster_result) == 0){
  200. echo "<tr>";
  201. echo "<td></td>";
  202. echo "<td></td>";
  203. echo "<td></td>";
  204. echo "<td></td>";
  205. echo "</form>";
  206. echo "</tr>";
  207. }
  208. else{
  209. while($row=mysql_fetch_array($xy_roster_result)){
  210. echo "<tr>";
  211. echo "<form action='unenroll.php' method='post'>";
  212. echo "<input name='id' type='hidden' value='" . $row['id'] . "' />";
  213. echo "<input name='student_id' type='hidden' value=" . $row['users_id'] . " />";
  214. echo "<input name='teacher_id' type='hidden' value='$userid' />";
  215. echo "<input name='xy_id' type='hidden' value='" . $xyassid . "' />";
  216. echo "<input name='type' type='hidden' value='xy' />";
  217. echo "<td>" . $row['lastname'] . "</td>";
  218. echo "<td>" . $row['firstname'] . "</td>";
  219. echo "<td>" . $row['username'] . "</td>";
  220. echo "<td><button class='btn btn-medium btn-warning' type='submit'>Remove</button></td>";
  221. echo "</form>";
  222. echo "</tr>";
  223. }
  224. }
  225. ?>
  226. </tbody>
  227. </table>
  228. </div>
  229. <div class="span4">
  230. <h3>Available Students</h3>
  231. <table class="table table-striped table-hover table-condensed">
  232. <thead>
  233. <tr>
  234. <th>Last Name</th>
  235. <th>First Name</th>
  236. <th>Username</th>
  237. <th></th>
  238. </tr>
  239. </thead>
  240. <tbody>
  241. <?php
  242. if (mysql_num_rows($students_result) == 0){
  243. echo "<tr>";
  244. echo "<td></td>";
  245. echo "<td></td>";
  246. echo "<td></td>";
  247. echo "<td></td>";
  248. echo "</form>";
  249. echo "</tr>";
  250. }
  251. else{
  252. while($row=mysql_fetch_array($students_result)){
  253. echo "<tr>";
  254. echo "<form action='enroll.php' method='post'>";
  255. echo "<input name='id' type='hidden' value=" . $row['id'] . " />";
  256. echo "<input name='teacher_id' type='hidden' value='$userid' />";
  257. echo "<input name='type' type='hidden' value='xy' />";
  258. echo "<input name='xy_id' type='hidden' value='" . $xyassid . "' />";
  259. echo "<td>" . $row['lastname'] . "</td>";
  260. echo "<td>" . $row['firstname'] . "</td>";
  261. echo "<td>" . $row['username'] . "</td>";
  262. echo "<td><button class='btn btn-medium btn-primary' type='submit'>Enroll</button></td>";
  263. echo "</form>";
  264. echo "</tr>";
  265. }
  266. }
  267. ?>
  268. </tbody>
  269. </table>
  270. </div>
  271. </div>
  272. </section>
  273. <?php
  274. }
  275. mysql_close();
  276. ?>
  277. </div>
  278. </div>
  279. </body>
  280. </html>