diff --git a/Quizzer/Quizzer/Pages/Report.cshtml b/Quizzer/Quizzer/Pages/Report.cshtml
new file mode 100644
index 0000000..806f09f
--- /dev/null
+++ b/Quizzer/Quizzer/Pages/Report.cshtml
@@ -0,0 +1,91 @@
+@page
+@model Quizzer.Pages.ReportModel
+@Html.AntiForgeryToken()
+@{
+ ViewData["Title"] = "Quizzer";
+ Layout = "_Layout-teacher";
+}
+
+ @if (Model.PageStatistics != null)
+ { // Select a quiz to show the report for
+
+
+
+
+
+
+ |
+ Class |
+ Quizz |
+
+
+ @foreach (var item in Model.quizzList)
+ {
+
+ |
+
+ |
+ @item.Class |
+ @item.CategoryText |
+
+
+ |
+
+ }
+
+
+
+ }
+ else
+ { // Show the report for the selected quiz
+ @if (Model.PageStatistics.Questions.Count > 0 && Model.PageStatistics.MCList.Count > 0)
+ {
+
+
Statistics for @Model.SelectedClass (@Model.SelectedCat)
+ @for (int Qindex = 0; Qindex < Model.PageStatistics.Questions.Count; Qindex++)
+ {
+
+
+
+ | Count |
+ @Model.PageStatistics.Questions[Qindex].QuestionText |
+
+
+ @for (int Aindex = 0; Aindex < @Model.PageStatistics.Questions[Qindex].AList.Count; Aindex++)
+ {
+
+ | @Model.PageStatistics.MCList[Qindex].Counter[Aindex] |
+ @if (@Model.PageStatistics.Questions[Qindex].AList[Aindex].Aok)
+ {
+ @Model.PageStatistics.Questions[Qindex].AList[Aindex].Atxt |
+ }
+ else
+ {
+ @Model.PageStatistics.Questions[Qindex].AList[Aindex].Atxt |
+ }
+
+ }
+
+ }
+
+ }
+ else
+ {
+
+
No statistics available
+
+ }
+ }
+
diff --git a/Quizzer/Quizzer/Pages/Report.cshtml.cs b/Quizzer/Quizzer/Pages/Report.cshtml.cs
new file mode 100644
index 0000000..d7bdb22
--- /dev/null
+++ b/Quizzer/Quizzer/Pages/Report.cshtml.cs
@@ -0,0 +1,134 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.RazorPages;
+using Newtonsoft.Json;
+using Quizzer.Extensions;
+using Quizzer.Models;
+using Quizzer.OpenIDConnect;
+using Quizzer.Persistens;
+
+namespace Quizzer.Pages
+{
+ public class ReportModel : PageModel
+ {
+ [BindProperty]
+ public OpenIDUCNData ucnData { get; set; }
+
+ [BindProperty]
+ public string UserID { get; set; }
+
+ [BindProperty]
+ public List quizzList { get; set; }
+
+ [BindProperty]
+ public StatisticsMCDN PageStatistics { get; set; }
+
+ [BindProperty]
+ public string SelectedClass { get; set; }
+
+ [BindProperty]
+ public string SelectedCat { get; set; }
+
+ [BindProperty]
+ public string myFullName { get; set; }
+
+
+ private bool isDebug;
+ private string KCUserID { get; set; }
+
+ private DbOps dbManager = new();
+ private OpenIDConnectUtils OpenIDUtils = new();
+
+
+ public string reportCookie { get; set; }
+
+ private const string cookieName = "ReportCookie";
+
+ private void GetMyCookie()
+ {
+ string jsonString = HttpContext.Request.Cookies[cookieName];
+ if (jsonString != null)
+ {
+ reportCookie = JsonConvert.DeserializeObject(jsonString);
+ return;
+ }
+ // Here if no cookie found
+ reportCookie = "";
+ // Save the new cookie
+ SetMyCookie();
+ }
+
+ private void SetMyCookie()
+ {
+ string jsonResult = JsonConvert.SerializeObject(reportCookie);
+ Response.Cookies.Append(cookieName, jsonResult, new Microsoft.AspNetCore.Http.CookieOptions
+ {
+ Secure = true,
+ HttpOnly = true,
+ SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None,
+ });
+ }
+
+ private void RemoveMyCookie()
+ {
+ Response.Cookies.Delete(cookieName);
+ }
+
+
+ //
+
+
+ public void Common()
+ {
+ isDebug = MyConfiguration.Get()["DEBUG"] == "Y";
+ string? ucnDataJson = OpenIDUtils.GetJwtClaim(HttpContext, "ucn");
+
+ KCUserID = OpenIDUtils.GetJwtClaim(HttpContext, "sub");
+ ucnData = JsonConvert.DeserializeObject(ucnDataJson);
+ UserID = OpenIDUtils.GetJwtClaim(HttpContext, "email").HashSHA256();
+ myFullName = OpenIDUtils.GetJwtClaim(HttpContext, "name");
+ }
+
+
+ public IActionResult OnGet()
+ {
+ Common();
+ if (ucnData.theRole != "teacher" && ucnData.theRole != "developer") return Redirect("/");
+ GetMyCookie();
+ quizzList = dbManager.GetQuizzesTeacher(UserID);
+ if (reportCookie != "")
+ {
+ // traverse all statistics
+ PageStatistics = dbManager.GetStatisticsMCDN(reportCookie);
+ // Show the report for the selected quiz while making sure a reload will reset for a new selection
+ Quizz selectedQuiz = dbManager.GetQuizz(reportCookie);
+ SelectedClass = selectedQuiz.Class;
+ Cat selectedCat = dbManager.GetCat(selectedQuiz.Category);
+ SelectedCat = selectedCat.Txt;
+ RemoveMyCookie();
+ }
+ else
+ {
+ PageStatistics = null;
+ }
+ return Page();
+ }
+
+ public IActionResult OnPost(string action = "na", string changeTo = "na")
+ {
+ Common();
+ GetMyCookie();
+ switch (action)
+ {
+ case "selectQuizz":
+ reportCookie = changeTo;
+ break;
+ case "na":
+ break;
+ default:
+ break;
+ }
+ SetMyCookie();
+ return Redirect("/Report");
+ }
+ }
+}
diff --git a/Quizzer/Quizzer/Pages/Shared/_Layout-teacher.cshtml b/Quizzer/Quizzer/Pages/Shared/_Layout-teacher.cshtml
index 4af1d42..a0065c3 100644
--- a/Quizzer/Quizzer/Pages/Shared/_Layout-teacher.cshtml
+++ b/Quizzer/Quizzer/Pages/Shared/_Layout-teacher.cshtml
@@ -31,6 +31,9 @@
Statistics
+
+ Report
+
Coverage
diff --git a/Quizzer/Quizzer/Pages/Shared/_Layout.cshtml b/Quizzer/Quizzer/Pages/Shared/_Layout.cshtml
index cbc6a3f..1662853 100644
--- a/Quizzer/Quizzer/Pages/Shared/_Layout.cshtml
+++ b/Quizzer/Quizzer/Pages/Shared/_Layout.cshtml
@@ -35,6 +35,9 @@
Statistics
+
+ Report
+
Coverage