PageRenderTime 24ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/XDataGrading/WebContent/Student/ListOfQuestions.jsp

https://gitlab.com/xdata/xdata-web
JavaServer Pages | 416 lines | 362 code | 40 blank | 14 comment | 52 complexity | 3ff88685480d87c1ad340ae8c0959f0f MD5 | raw file
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8" errorPage="errorPage.jsp"%>
  3. <%@ page import="java.io.*"%>
  4. <%@ page import="java.util.*"%>
  5. <%@page import="java.sql.*"%>
  6. <%@ page import="java.text.*"%>
  7. <%@page import="database.DatabaseConnection"%>
  8. <%@page import="database.CommonFunctions"%>
  9. <%@page import="database.DatabaseProperties"%>
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  11. <html>
  12. <head>
  13. <link rel="stylesheet" href="../css/structure.css" type="text/css"/>
  14. <link rel="stylesheet" href="../highlight/styles/xcode.css">
  15. <link rel="stylesheet" href="../highlight/styles/default.css">
  16. <script type="text/javascript" src = "../scripts/jquery.js"></script>
  17. <script src="../highlight/highlight.pack.js"></script>
  18. <script type="text/javascript">
  19. hljs.initHighlightingOnLoad();
  20. </script>
  21. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  22. <title>List Of Questions</title>
  23. <style>
  24. textarea,select {
  25. font: 12px/12px Arial, Helvetica, sans-serif;
  26. padding: 0;
  27. }
  28. .questionelement .answer .editbutton a{
  29. text-decoration:none;
  30. color: #353275;
  31. float:left;
  32. }
  33. .separator{
  34. border-right:1px solid black;
  35. margin:0px;
  36. float: right;
  37. margin-right: 3px;
  38. width:1px;
  39. margin-left: 2px;
  40. }
  41. pre {
  42. font-family: "Lucida Grande", Tahoma, Arial, Verdana, sans-serif;
  43. }
  44. input {
  45. font: 15px/15px Arial, Helvetica, sans-serif;
  46. padding: 0;
  47. }
  48. fieldset.action {
  49. background: #9da2a6;
  50. border-color: #e5e5e5 #797c80 #797c80 #e5e5e5;
  51. margin-top: -20px;
  52. }
  53. .stop-scrolling {
  54. height: 100%;
  55. /* overflow: hidden; */
  56. }
  57. #breadcrumbs
  58. {
  59. position: absolute;
  60. padding-left:10px;
  61. padding-right:10px;
  62. left: 5px;
  63. top: 10px;
  64. font: 13px/13px Arial, Helvetica, sans-serif;
  65. background-color: #f0f0f0;
  66. font-weight: bold;
  67. }
  68. </style>
  69. </head>
  70. <body>
  71. <%
  72. if (session.getAttribute("LOGIN_USER") == null) {
  73. response.sendRedirect("index.jsp?TimeOut=true");
  74. return;
  75. }
  76. if(! Boolean.parseBoolean(session.getAttribute("ltiIntegration").toString())){
  77. %>
  78. <div id="breadcrumbs">
  79. <a style='color:#353275;text-decoration: none;' href="../CourseHome.jsp" target="_top">Home</a> &nbsp; >> &nbsp;
  80. <a style='color:#353275;text-decoration: none;' href="ListAllAssignments.jsp" target="_self">Assignment List</a>&nbsp; >> &nbsp;
  81. <a href="#" style='color:#0E0E0E;text-decoration: none;font-weight: normal;'>Question List</a>
  82. </div>
  83. <%} %>
  84. <div><br/>
  85. <div class="fieldset">
  86. <fieldset>
  87. <%if(((String)session.getAttribute("LOGIN_USER")).equalsIgnoreCase("guest") ){%>
  88. <!-- <legend> Assignment Details</legend> -->
  89. <%}else{%>
  90. <legend> Assignment Details</legend>
  91. <%}%>
  92. <%
  93. String courseID = (String) request.getSession().getAttribute(
  94. "context_label");
  95. String user =(String) request.getSession().getAttribute(
  96. "LOGIN_USER");
  97. int assignID = Integer.parseInt(request.getParameter("assignmentid"));
  98. String instructions = (new CommonFunctions()).getStudentAssignmentInstructions(courseID, assignID, user);
  99. out.println(instructions);
  100. %>
  101. </fieldset>
  102. <fieldset>
  103. <legend> Assignment Instructions</legend>
  104. <%if(((String)session.getAttribute("LOGIN_USER")).equalsIgnoreCase("guest") ){%>
  105. <ul>
  106. <li>Click edit to enter your answer. The selection conditions are case sensitive</li>
  107. <li>Please take a look on <a href='../images/universitySchema.pdf' target='_blank'>Schema diagram</a> of the default schema being used</li>
  108. </ul>
  109. <%}else{%>
  110. <ul>
  111. <li>Click edit to enter your answer</li>
  112. <li>Be cautious, the selection conditions are case sensitive</li>
  113. <li>On editing, the query will be run against datasets</li>
  114. <li>You will be forwarded to a page where the result of submission would be shown</li>
  115. <li>Please take a look on <a href='../images/universitySchema.pdf' target='_blank'>Schema diagram</a> of the default schema being used</li>
  116. </ul>
  117. <%}%>
  118. <p></p>
  119. </fieldset>
  120. <br/>
  121. <fieldset>
  122. <legend> List of Questions </legend>
  123. <%
  124. List <Integer> schemaIdList = new ArrayList();
  125. int defaultSchemaID=0;
  126. boolean questionGraded = false;
  127. int optionalSchemaID =0;
  128. boolean isShowQuestions = false;
  129. boolean isInteractiveAssignment = false;
  130. boolean showmarks = false;
  131. String schemaFileName = "";
  132. String dataFileName="";
  133. String studentId = (String) request.getParameter("studentId");
  134. String status = request.getParameter("status");
  135. if (studentId == null)
  136. studentId = (String) request.getSession().getAttribute(
  137. "user_id");
  138. //get connection
  139. Connection dbcon = (new DatabaseConnection()).dbConnection();
  140. Timestamp start = null;
  141. Timestamp end = null;
  142. try {
  143. PreparedStatement stmt;
  144. ResultSet rs = null;
  145. stmt = dbcon
  146. .prepareStatement("SELECT * FROM xdata_assignment where assignment_id=? and course_id=?");
  147. stmt.setInt(1, assignID);
  148. stmt.setString(2, courseID.trim());
  149. rs = stmt.executeQuery();
  150. while (rs.next()) {
  151. start = rs.getTimestamp("starttime");
  152. end = rs.getTimestamp("endtime");
  153. defaultSchemaID = rs.getInt("defaultschemaid");
  154. isInteractiveAssignment = rs.getBoolean("learning_mode");
  155. showmarks = rs.getBoolean("showmarks");
  156. //start=rs.getString("end_date");
  157. }
  158. schemaIdList.add(defaultSchemaID);
  159. rs.close();
  160. stmt.close();
  161. } catch (Exception err) {
  162. err.printStackTrace();
  163. throw new ServletException(err);
  164. }
  165. //now check whether current time is less than start time.Then only assignment can be edited
  166. boolean yes = false;
  167. SimpleDateFormat formatter = new SimpleDateFormat(
  168. "yyyy-MM-dd HH:mm:ss");
  169. formatter.setLenient(false);
  170. String ending = formatter.format(end);
  171. String starting = formatter.format(start);
  172. //String oldTime = "2012-07-11 10:55:21";
  173. java.util.Date oldDate = formatter.parse(ending);
  174. java.util.Date strtDate = formatter.parse(starting);
  175. //get current date
  176. Calendar c = Calendar.getInstance();
  177. String currentDate = formatter.format(c.getTime());
  178. java.util.Date current = formatter.parse(currentDate);
  179. //compare times
  180. if (current.compareTo(oldDate) > 0 && showmarks == true) {
  181. yes = true;
  182. }
  183. //Is current time is less than assignment strt time, dont show the questions.
  184. if(current.compareTo(strtDate) > 0){
  185. isShowQuestions = true;
  186. }
  187. //String output = "<table cellspacing=\"20\" class=\"authors-list\" id=\"queryTable\" align=\"center\"> <tr> <th >Question ID</th> <th >Question Description</th> <th >Your Answer</th> <th> </th></tr>";
  188. String output= "";
  189. try {
  190. if(isShowQuestions){
  191. int q_index=0;
  192. PreparedStatement stmt1;
  193. //stmt = dbcon.prepareStatement("SELECT * FROM xdata_qinfo ,assignment where qinfo.assignment_id=? AND qinfo.assignment_id=assignment.assignment_id");
  194. stmt1 = dbcon
  195. .prepareStatement("SELECT * FROM xdata_qinfo where assignment_id=? and course_id=? order by question_id");
  196. stmt1.setInt(1, assignID);
  197. stmt1.setString(2, courseID.trim());
  198. ResultSet rs1 = stmt1.executeQuery();
  199. while (rs1.next()) {
  200. int qID = rs1.getInt("question_id");
  201. q_index++;
  202. //System.out.println(qID);
  203. String desc = rs1.getString("querytext");
  204. optionalSchemaID = rs1.getInt("optionalschemaid");
  205. if(optionalSchemaID != defaultSchemaID){%>
  206. <script>
  207. document.getElementById(<%=assignID%>).style.display='block';
  208. </script>
  209. <%}
  210. stmt1 = dbcon
  211. .prepareStatement("SELECT * FROM xdata_student_queries where assignment_id=? and question_id=? and rollnum=?");
  212. String queryId = "A" + assignID + "Q"+qID+"S1";
  213. stmt1.setInt(1, assignID);
  214. stmt1.setInt(2,qID);
  215. stmt1.setString(3, studentId.trim());
  216. ResultSet rs2 = stmt1.executeQuery();
  217. boolean verified = false;
  218. String studentAnswer = "";
  219. if (rs2.next()){
  220. studentAnswer = rs2.getString("querystring");
  221. if(rs2.getString("verifiedcorrect") != null){
  222. verified = rs2.getBoolean("verifiedcorrect");
  223. questionGraded = true;
  224. }else{
  225. //if(rs2.getString("result") != null){
  226. verified = false;
  227. questionGraded = false;
  228. }
  229. }
  230. String isCorrect = "Incorrect";
  231. if(verified) isCorrect = "Correct";
  232. String remote = "QuestionDetails.jsp?AssignmentID="
  233. + assignID + "&&courseId=" + courseID
  234. + "&&questionId=" + qID + "&&studentId="
  235. + studentId + "\" target = \"rightPage\"";
  236. String viewGrade = "ViewGradesOfAssignment.jsp?AssignmentID="
  237. + assignID + "&&courseId=" + courseID
  238. + "&&questionId=" + qID + "&&studentId="
  239. + studentId + "\" target = \"rightPage\"";
  240. if (yes == false){
  241. output += "<tr><td>Question: "
  242. + qID
  243. + "</td>"
  244. + "<td>"
  245. + desc
  246. + "</td>"
  247. + "<td>"
  248. + CommonFunctions.encodeHTML(studentAnswer)
  249. + "</td>"
  250. + "<td><input type=\"button\" onClick=\"window.location.href='"
  251. + remote + " value=\"Edit\" > <br/> \n ";
  252. }
  253. else{
  254. output += CommonFunctions.encodeHTML(studentAnswer)
  255. // + "</td><br/> \n";
  256. + "<td><input type=\"button\" onClick=\"window.location.href='"
  257. + viewGrade
  258. + " value=\"View Grade\" > <br/> \n";
  259. }
  260. rs2.close();
  261. %>
  262. <div class="questionelement">
  263. <div class="question"><span>Q<%= q_index %>. </span><pre class="question"><%= desc %></pre>
  264. <!-- Test optionalSchema = <%//=optionalSchemaID %> -->
  265. <%if(optionalSchemaID != defaultSchemaID && !schemaIdList.contains(optionalSchemaID)){
  266. //Add schema id to the list if it is encountered first time and show link to download
  267. schemaIdList.add(optionalSchemaID);
  268. PreparedStatement state = dbcon.prepareStatement("select sample_data_name from xdata_sampledata where schema_id=? and course_id=?");
  269. state.setInt(1,optionalSchemaID);
  270. state.setString(2,courseID);
  271. ResultSet result= state.executeQuery();
  272. PreparedStatement statemnt = dbcon.prepareStatement("select schema_name from xdata_schemainfo where schema_id=? and course_id=?");
  273. statemnt.setInt(1,optionalSchemaID);
  274. statemnt.setString(2,courseID);
  275. ResultSet resultrs= statemnt.executeQuery();
  276. if(resultrs.next()){
  277. %><div>
  278. <a class="getFile" href="../showSchemaFile.jsp?schema_id=<%=optionalSchemaID%>" >
  279. <%=resultrs.getString("schema_name") %></a>&nbsp;&nbsp;&nbsp;&nbsp;
  280. <%if(result.next()){%>
  281. <a class="getFile" href="../showSampleData.jsp?schema_id=<%=optionalSchemaID%>" >
  282. <%=result.getString("sample_data_name") %></a>
  283. <%}%>
  284. </div>
  285. <%}
  286. }%>
  287. </div>
  288. <div class="answer">
  289. <pre><code class="sql"><label style="font-style:bold;font-weight: bold">Ans. </label><%= studentAnswer %></code></pre>
  290. </div></br>
  291. <%if(user.equalsIgnoreCase("guest")){ %>
  292. <div class="editbutton" ><a style="text-decoration:none;color: #353275;float:left;padding-left:20px;" href="<%=yes?viewGrade:remote %>"><%=yes?"View Grade":"Edit" %></a>
  293. <%}else{ %>
  294. <div class="editbutton" ><a style="text-decoration:none;color: #353275;float:right;padding-left:20px;" href="<%=yes?viewGrade:remote %>"><%=yes?"View Grade":"Edit" %></a>
  295. <%} %>
  296. <% if(studentAnswer != null && !yes && studentAnswer.length() > 0 && isInteractiveAssignment && !user.equalsIgnoreCase("guest")){ %>
  297. <a href='../StudentTestCase?user_id=<%=studentId%>&&assignment_id=<%=assignID %>&&question_id=<%=qID %>&&status=<%=isCorrect%>&&query=<%=CommonFunctions.encodeURIComponent(studentAnswer)%>&&Error=Incorrect Query Syntax'>Show Result</a>
  298. <%}
  299. if(!user.equalsIgnoreCase("guest")) {%>
  300. <div class = "status"><span style='font-weight:bold;'>Status:</span>
  301. <% if(verified && questionGraded){ %>
  302. <font color='green'> Ok
  303. <%}
  304. else if(!questionGraded){
  305. %>
  306. <font color='#353275'> Not Graded
  307. <%
  308. }
  309. else if(!verified &&
  310. (studentAnswer == null ||(studentAnswer !=null && studentAnswer.isEmpty())))
  311. { %>
  312. <font color='#353275'> Not Graded
  313. <%}else {%>
  314. <font color='red'> Incorrect
  315. <%}
  316. %>
  317. </font></div>
  318. </div>
  319. <% }else{%>
  320. </div>
  321. <%}
  322. }
  323. rs1.close();
  324. stmt1.close();
  325. output = "";
  326. }
  327. else {
  328. %>
  329. <div class="questionelement">
  330. <label>
  331. <font color='#353275'>The assignment starts on <%=strtDate%>. Please wait till the start time to view the questions.
  332. </font>
  333. </label>
  334. </div>
  335. <%
  336. }
  337. if(status != null){
  338. if(status.equals("NoDataset")){
  339. }
  340. else if(status.equals("Correct")){
  341. output += "<p>Passed test cases</p>";
  342. }
  343. else if(status.equals("Error")){
  344. output += "<p style=\"color:red;\">Error occurred. Please ensure:</p>"
  345. +"<ul>"
  346. + "<li>The query syntax is correct</li>"
  347. +"<ul>";
  348. }
  349. else if(status.equals("Incorrect")){
  350. output += "<p style=\"color:red;\">Test case failed. Please ensure:</p>"
  351. +"<ul><li>You have submitted only the query without any comments or results</li>"
  352. + "<li>The query syntax is correct</li>"
  353. + "<li>The query does not use any specific schema name</li>"
  354. + "<li>The order of projected columns</li>"
  355. + "<li>Check query predicates</li>"
  356. +"<ul>";
  357. }
  358. else if(status.equals("expired")){
  359. output += "<p>Submission not saved. Assignment expired.</p>";
  360. }
  361. }
  362. out.println(output);
  363. } catch (Exception err) {
  364. err.printStackTrace();
  365. throw new ServletException(err);
  366. }
  367. finally{
  368. if(dbcon != null)
  369. dbcon.close();
  370. }
  371. %>
  372. </fieldset>
  373. </div>
  374. </div>
  375. </body>
  376. </html>