0% found this document useful (0 votes)
8 views194 pages

Game Code

The document contains Java code for a web application using Spring framework, focusing on game functionality and student management. It includes configuration for Thymeleaf templates, controllers for handling game logic, student operations, and quiz management. Key features include starting and ending games, managing student profiles, and handling quiz questions and scores.

Uploaded by

Bot 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views194 pages

Game Code

The document contains Java code for a web application using Spring framework, focusing on game functionality and student management. It includes configuration for Thymeleaf templates, controllers for handling game logic, student operations, and quiz management. Key features include starting and ending games, managing student profiles, and handling quiz questions and scores.

Uploaded by

Bot 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 194

Appendix E: Code

Class: ThymeleafConfig

package io.flappybird.configration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.spring6.SpringTemplateEngine;
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.templatemode.TemplateMode;

@Configuration
public class ThymeleafConfig {

@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
return templateEngine;
}

@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new
SpringResourceTemplateResolver();
templateResolver.setPrefix("classpath:/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
return templateResolver;
}
}

Class: GameController

package io.flappybird.controller.game;

import io.flappybird.game.App;
import io.flappybird.game.Game;
import io.flappybird.model.*;
import io.flappybird.service.*;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

1
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.io.*;
import java.util.List;
@Controller
@RequestMapping("/game")
public class GameController {

@Autowired
QuestionService questionService;
@Autowired
private QuizService quizService;

@Autowired
private PlayGameService playGameService;

@Autowired
private TopicService topicService;
private int highScore = 0;

@GetMapping("/playGame")
public String playGame(RedirectAttributes redirectAttributes,Model model) throws
Exception {
List<TopicDDLReq> topicDDLReq= quizService.bindTopicList("DD1");
model.addAttribute("topics", topicDDLReq);
Game game = new Game();
int hs = game.findHighScore();
SessionManager.getInstance().setHighestScore(hs);
ScoreReq scoreReq = playGameService.bindScore();
System.out.println("getHighestScore>>>"+scoreReq.getHighestScore()+
"getRecentScore>>>"+scoreReq.getRecentScore());
model.addAttribute("scoreReq", scoreReq);
return "game/startGame";
}

@GetMapping("/readMe")
@ResponseBody
public String readMe() {
StringBuilder readMeContent = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new FileReader("ReadMe.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
readMeContent.append(line).append("<br/>"); // Append each line and add line
break
}

2
} catch (Exception e) {
e.printStackTrace(); // Handle exceptions appropriately
return "Error loading instructions.";
}
return readMeContent.toString(); // Return the full content as a string
}
@GetMapping("/deleteHighestScore")
public String deleteHighestScore(RedirectAttributes redirectAttributes) throws Exception {
System.out.println("deleteHighestScore Calling>>>>>>>>>>>>>>");

RandomAccessFile file = new RandomAccessFile("highscores.dat", "rw");


RandomAccessFile tempFile = new RandomAccessFile("temp.dat", "rw");

try {
while (file.getFilePointer() < file.length()) {
int score = file.readInt();
System.out.println("deleteHighestScore Calling>>>>>>score>>>>>>>>" + score);
if (score != SessionManager.getInstance().getHighestScore()) {
tempFile.writeInt(score); // Write to temporary file
}
}
} finally {
file.close();
tempFile.close();
}

File oldFile = new File("highscores.dat");


File newFile = new File("temp.dat");

if (oldFile.delete()) {
newFile.renameTo(oldFile);
} else {
throw new Exception("Failed to delete old highscores file");
}

Game game = new Game();


int hs = game.findHighScore();
SessionManager.getInstance().setHighestScore(hs);

System.out.println("High Score Deleted successfully!");


redirectAttributes.addFlashAttribute("message", "High Score Deleted successfully!");
return "redirect:/teacher/studentWisePerformance";
}
@GetMapping("/game/{selectedQuizId}")
public String gameStart(Model model, RedirectAttributes redirectAttributes,
@PathVariable("selectedQuizId") int selectedQuizId, HttpSession session) {
String userName= SessionManager.getInstance().getUsername();
List<QuestionsReq> questionReqs=bindQuestionsInfo(selectedQuizId);

3
SessionManager.getInstance().setQuestions(questionReqs);
model.addAttribute("userName", userName);
App app;
if(! SessionManager.getInstance().isGameOpen()) {
app=new App();
app.startGame();
SessionManager.getInstance().setGameOpen(true);
}
else {
String resultMessage="Game Already Open Pl";
redirectAttributes.addFlashAttribute("delMsg", resultMessage);

return "student/studentMenu";
}
@GetMapping("/quizzes/{topicId}")
@ResponseBody
public List<QuizDDLReq> getQuizzesForTopic(@PathVariable("topicId") int topicId) {
System.out.println("topicId>>>>>>>>>>>>>"+topicId);
List<QuizDDLReq> quizDDLReq= quizService.getQuizListByTopics("DD3",topicId);
System.out.println("quizDDLReq>>>>>>>>>>>>>"+quizDDLReq);
return quizDDLReq;
}

@GetMapping("/questions/{quizId}")
@ResponseBody
public List<QuestionsReq> bindQuestionsInfo(@PathVariable("quizId") int quizId) {

SessionManager.getInstance().setQuizIdS(0);//default value
SessionManager.getInstance().setQuizIdS(quizId);//default value
return
questionService.bindQuestionsInfo("DG2",SessionManager.getInstance().getUserId(),quizId)
;
}
//Start Game
@PostMapping("/startGame")
public String startGame( @RequestBody PlayGameReq playGameReq,
RedirectAttributes redirectAttributes,BindingResult bindingResult) {
System.out.println("playGameReq");
String resultMsg=playGameService.startGame(playGameReq);
int userTypeId = SessionManager.getInstance().getUserTypeId();//1: student,3:Teacher
if(resultMsg.equals("SUCCESS"))
{
​ //
}
else{
redirectAttributes.addFlashAttribute("errorMsg", resultMsg);

4
}
return "redirect:/game/startGame";
}
//End Game
@PostMapping("/endGame")
public String endGame( @RequestBody PlayGameReq playGameReq, RedirectAttributes
redirectAttributes) {
String resultMsg = playGameService.endGame(playGameReq);
if (resultMsg.equals("SUCCESS")) {
} else {
redirectAttributes.addFlashAttribute("errorMsg", resultMsg);
}
return "redirect:/game/startGame";
}

}
Class: StudentController

package io.flappybird.controller.student;
import com.fasterxml.jackson.databind.ext.Java7Handlers;
import io.flappybird.model.*;
import io.flappybird.service.SessionManager;
import io.flappybird.service.StudentService;
import io.flappybird.service.TopicService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {

@Autowired
private StudentService studentService;
@Autowired
private TopicService topicService;
@GetMapping("/achievements")
public String achievements(Model model) {
int userId = SessionManager.getInstance().getUserId();
AchievementsReq achievementsReq= studentService.bindAchievements("ACH",userId);
model.addAttribute("achievementsReq", achievementsReq);
return "student/achievements";
}
@GetMapping("/studentMenu")
public String studentMenu(Model model) {
String userName= SessionManager.getInstance().getUsername();

5
model.addAttribute("userName", userName);
return "student/studentMenu";
}
@PostMapping("/InsertStudent")
public String saveStudent(@ModelAttribute StudentReq student, RedirectAttributes
redirectAttributes) {
redirectAttributes.addFlashAttribute("message", "Student added successfully!");
return "redirect:/students";
}
@GetMapping("/bindStudentInfo")
public String bindStudentInfo(Model model) {
List<StudentReq> studentReq= studentService.bindStudentInfo("DG1");
model.addAttribute("students", studentReq);
return "student/Student";
}
@GetMapping("/studentPerformance")
public String studentPerformance(Model model) {
int userId = SessionManager.getInstance().getUserId();
List<TopicStatusReq> topicStatusReq= topicService.topicsStatus("SPS",userId);
model.addAttribute("topicStatusReq", topicStatusReq);
return "student/studentPerformance";
}
@GetMapping("/topicsStatus")
public String topicsStatus(Model model) {
int userId = SessionManager.getInstance().getUserId();
List<TopicStatusReq> topicStatusReq= topicService.topicsStatus("STS",userId);
model.addAttribute("topicStatusReq", topicStatusReq);
return "student/topicsStatus";
}

@GetMapping("/updateStudentProfile")
public String updateStudentProfile(Model model) {
int userId = SessionManager.getInstance().getUserId();
UpdateStudentProfileReq updateStudentProfileReq =
studentService.getStudentByUserId(userId);
List<GradeMasterReq> gradeMasterReqs= studentService.bindDdlGrade("DD1");
List<GenderMasterReq> genderMasterReqs= studentService.bindDdlGender("DD2");
model.addAttribute("updateStudentProfileReq", updateStudentProfileReq);
model.addAttribute("updateStudentProfileReqBind", new UpdateStudentProfileReq());
model.addAttribute("grades", gradeMasterReqs);
model.addAttribute("genders", genderMasterReqs);
return "student/updateStudentProfile";
}
@PostMapping("/updateStudentProfile")
public String updateStudentProfile(@Valid @ModelAttribute UpdateStudentProfileReq
updateStudentProfileReq, RedirectAttributes redirectAttributes) {
String resultMsg = studentService.updateStudentProfile(updateStudentProfileReq);
if (resultMsg.equals("SUCCESS")) {
redirectAttributes.addFlashAttribute("message", "Student Profile Updated successfully!");
} else {
redirectAttributes.addFlashAttribute("errorMsg", resultMsg);
}

6
return "redirect:/student/updateStudentProfile";
}
@GetMapping("/new")
public String createStudentForm(Model model) {
model.addAttribute("student", new StudentReq());
List<GradeMasterReq> gradeMasters=studentService.bindDdlGrade("DD1");
model.addAttribute("grades", gradeMasters);
return "create_student";
}

@GetMapping("/edit/{id}")
public String editStudentForm(@PathVariable("id") int id, Model model) {
StudentReq students = studentService.getStudentId("GET",id);
List<GradeMasterReq> gradeMasters=studentService.bindDdlGrade("DD1");
model.addAttribute("grades", gradeMasters);
model.addAttribute("student", students);
return "user/studentInfo";
}

@PostMapping("/update")
public String updateStudent(@ModelAttribute StudentReq student, RedirectAttributes
redirectAttributes) {
redirectAttributes.addFlashAttribute("message", "Student updated successfully!");
return "redirect:/students";
}

@GetMapping("/delete/{id}")
public String deleteStudent(@PathVariable("id") Integer id, RedirectAttributes
redirectAttributes,Model model) {
String resultMessage= studentService.deleteStudendInfo("DAC",id);
redirectAttributes.addFlashAttribute("delMsg", resultMessage);
return "redirect:/user/studentInfo";
}

@GetMapping("/grade")
public String getGrades(Model model) {
model.addAttribute("grades", studentService.bindDdlGrade("DD1"));
return "students";
}

Class: QuestionController

package io.flappybird.controller.teacher;
import io.flappybird.model.PlayGameReq;
import io.flappybird.model.QuestionsReq;
import io.flappybird.service.PlayGameService;
import io.flappybird.service.QuestionService;
import io.flappybird.service.SessionManager;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;

7
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController {
@Autowired
private QuestionService questionService;
@Autowired
private PlayGameService playGameService;

@GetMapping
public String bindQuestionInfo(Model model) {
return "Question";
}
@PostMapping("/next")
public QuestionsReq getNextQuestion(HttpSession session) {
List<QuestionsReq> questions = SessionManager.getInstance().getQuestions();
Integer currentQuestionIndex = SessionManager.getInstance().getCurrentQuestionIndex();
if (questions != null && currentQuestionIndex < questions.size()) {
QuestionsReq nextQuestion = questions.get(currentQuestionIndex);
// Increment index for the next call
SessionManager.getInstance().setCurrentQuestionIndex(currentQuestionIndex + 1);
return nextQuestion;
}
return null; // No more questions
}

@PostMapping("/submitAnswer")
public void submitAnswer(@RequestParam String selectedAnswer, HttpSession session) {
List<QuestionsReq> questions = (List<QuestionsReq>) session.getAttribute("questions");
Integer currentQuestionIndex = (Integer) session.getAttribute("currentQuestionIndex");
Integer score = (Integer) session.getAttribute("score");

if (currentQuestionIndex > 0) {
QuestionsReq currentQuestion = questions.get(currentQuestionIndex - 1);
if (String.valueOf(currentQuestion.getAnswer()).equals(selectedAnswer)) {
score++;
}
session.setAttribute("score", score);
}
}
@PostMapping("/startGame")
public String startGame( @RequestBody PlayGameReq playGameReq) {
System.out.println("playGameReq");
String resultMsg=playGameService.startGame(playGameReq);

int userTypeId = SessionManager.getInstance().getUserTypeId();//1: student,3:Teacher


if(resultMsg.equals("SUCCESS"))
{

8
//
}
else{

}
return "Yes";
}
}

Class: QuizController

package io.flappybird.controller.teacher;
import io.flappybird.model.QuizReq;
import io.flappybird.service.QuizService;
import io.flappybird.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/quizs")
public class QuizController {
@Autowired
private QuizService quizService;
@Autowired
private TopicService topicService;

@GetMapping
public String bindQuizInfo(Model model) {
List<QuizReq> quizReq= quizService.bindQuizInfo("DG1");
model.addAttribute("quizzes", quizReq);
return "teacher/Quiz";
}
}

Class: TeacherController

package io.flappybird.controller.teacher;
import io.flappybird.model.*;
import io.flappybird.service.*;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

9
@Controller
@RequestMapping("/teacher")
public class TeacherController {
@Autowired
private TeacherService teacherService;
@Autowired
private TopicService topicService;
@Autowired
private StudentService studentService;

@Autowired
private QuestionService questionService;
@GetMapping("/teacherMenu")
public String teacherMenu(Model model) {
String userName= SessionManager.getInstance().getUsername();
model.addAttribute("userName", userName);
return "teacher/teacherMenu";
}
@GetMapping("/quiz")
public String quiz(Model model) {
model.addAttribute("user", new UserReq());
return "teacher/quiz";
}
@PostMapping("/quiz")
public String quiz(@ModelAttribute StudentReq student, RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("message", "Student added successfully!");
return "teacher/quiz";
}
@GetMapping("/question")
public String question(Model model) {

List<QuizDDLReq> quizDDLReq= questionService.bindQuizList("DD2");


model.addAttribute("quizDDLReq", quizDDLReq);
return "teacher/question";
}
@PostMapping("/question")
public String question(@ModelAttribute StudentReq student, RedirectAttributes redirectAttributes) {
redirectAttributes.addFlashAttribute("message", "Student added successfully!");
return "teacher/question";
}

@GetMapping("/questions/{quizId}")
@ResponseBody
public List<QuestionReq> getTopicsForStudentList(@PathVariable("quizId") int quizId) {
return
questionService.bindQuestionInfo("DG1",SessionManager.getInstance().getUserId(),quizId);
}
@GetMapping("/topics/{studentId}")
@ResponseBody
public List<TopicStatusReq> topicsStatus(@PathVariable("studentId") int studentId) {
return topicService.topicsStatus("SPS",studentId);

10
}
@GetMapping("/studentWisePerformance")
public String studentWisePerformance(Model model) {
int userId = SessionManager.getInstance().getUserId();
List<StudentDDLReq> StudentDDLReq= studentService.bindStudentList("DD3");
model.addAttribute("students", StudentDDLReq);
return "teacher/studentWisePerformance";
}

@PostMapping("/studentWisePerformance")
public String studentWisePerformance(@PathVariable("id") int id, Model model) {
List<TopicStatusReq> topicStatusReq= topicService.topicsStatus("SPS",id);
return "teacher/studentWisePerformance";
}
@GetMapping("/updateTeacherProfile")
public String updateTeacherProfile(Model model) {
int userId = SessionManager.getInstance().getUserId();
UpdateTeacherProfileReq updateTeacherProfileReq=
teacherService.getTeacherByUserId(userId);
List<GenderMasterReq> genderMasterReqs= studentService.bindDdlGender("DD2");
model.addAttribute("updateTeacherProfileReq", updateTeacherProfileReq);
model.addAttribute("genders", genderMasterReqs);
return "teacher/updateTeacherProfile";
}
@PostMapping("/updateTeacherProfile")
public String updateTeacherProfile(@Valid @ModelAttribute UpdateTeacherProfileReq
updateTeacherProfileReq, RedirectAttributes redirectAttributes) {
System.out.println("st===Before
updateStudentProfile==============>"+updateTeacherProfileReq);
String resultMsg = teacherService.updateTeacherProfile(updateTeacherProfileReq);
if (resultMsg.equals("SUCCESS")) {
redirectAttributes.addFlashAttribute("message", "Teacher Profile Updated successfully!");
} else {
redirectAttributes.addFlashAttribute("errorMsg", resultMsg);
} return "teacher/updateTeacherProfile";
}
@GetMapping
public String bindTeacherInfo(Model model) {
return "teacher/Teacher";
}

Class: TopicController

package io.flappybird.controller.teacher;
import io.flappybird.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController

11
@RequestMapping("/topic")
public class TopicController {
@Autowired
private TopicService topicService;

@PostMapping("/add")
public String addTopic(@RequestParam String topicName, @RequestParam Integer userId) {
return topicService.addTopic(topicName, userId);
}

@PutMapping("/update")
public String updateTopic(@RequestParam Integer topicId, @RequestParam String topicName,
@RequestParam Integer isActive) {
return topicService.updateTopic(topicId, topicName, isActive);
}

@DeleteMapping("/deactivate/{id}")
public String deactivateTopic(@PathVariable("id") Integer topicId) {
return topicService.deactivateTopic(topicId);
}
}

Class: HomeController

package io.flappybird.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

@GetMapping("/")
public String home() {
return "redirect:user/login"; // Name of the Thymeleaf template (without .html)
}
}

Class: App

package io.flappybird.game;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import io.flappybird.model.PlayGameReq;
import io.flappybird.service.SessionManager;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class App {

12
private int currentScore = 0;
public static int WIDTH = 500;
public static int HEIGHT = 520;
public static JFrame frame;

public void startGame() {


SwingUtilities.invokeLater(() -> {
try {
// Create and set up the frame
frame = new JFrame("FLAPPY BIRD");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Set
DO_NOTHING_ON_CLOSE

// Handle the window closing event


frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Handle the window closing event
int option = JOptionPane.showConfirmDialog(
frame,
"Are you sure you want to exit?",
"Confirm Exit",
JOptionPane.YES_NO_OPTION
);
if (option == JOptionPane.YES_OPTION) {RestTemplate restTemplate = new
RestTemplate();

String url = "http://localhost:8080/game/endGame";


PlayGameReq playGameReq=new
PlayGameReq(SessionManager.getInstance().getQuizIdS(),
SessionManager.getInstance().getCorrectAnswer(),"Current
Quiz",SessionManager.getInstance().getUserId(),"127.0.01");
System.out.println("playGameReq========"+playGameReq);
String questions = restTemplate.postForObject(url, playGameReq, String.class);
SessionManager.getInstance().setCurrentQuestionIndex(0);//Start From first Question
SessionManager.getInstance().setCorrectAnswer(0);//SET Correct Answer COUNT =0
cleanupGameState();
frame.dispose(); // Dispose the frame and exit
SessionManager.getInstance().setGameOpen(false);
}
}
});

// Set frame properties


frame.setResizable(false);
frame.setSize(WIDTH, HEIGHT); // Use constants for size
frame.setLocationRelativeTo(null); // Center the frame
frame.setVisible(true); // Make the frame visible

Keyboard keyboard = Keyboard.getInstance();

13
frame.addKeyListener(keyboard);

GamePanel panel = new GamePanel();


frame.add(panel);
frame.setResizable(false);
frame.setSize(WIDTH, HEIGHT);
} catch (Exception e) {
e.printStackTrace();
}
});
}

private void cleanupGameState() {


Game.getInstance().restart();

public static void frameDispose(){


frame.dispose();
}

Class: Bird

package io.flappybird.game;

import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.geom.AffineTransform;

public class Bird {

public int x;
public int y;
public int width;
public int height;

public boolean dead;

public double yvel;


public double gravity;

private int jumpDelay;


private double rotation;

private Image image;


private Keyboard keyboard;

public Bird() {
x = 100;
y = 150;

14
yvel = 0;
width = 45;
height = 32;
gravity = 0.5;
jumpDelay = 0;
rotation = 0.0;
dead = false;

keyboard = Keyboard.getInstance();
}

public void update() {


yvel += gravity;

if (jumpDelay > 0)
jumpDelay--;

if (!dead && keyboard.isDown(KeyEvent.VK_SPACE) && jumpDelay <= 0) {


yvel = -10;
jumpDelay = 10;
}

y += (int)yvel;
}

public Render getRender() {


Render r = new Render();
r.x = x;
r.y = y;

if (image == null) {
image = Util.loadImage("src/main/resources/static/bird.png");
}
r.image = image;

rotation = (90 * (yvel + 20) / 20) - 90;


rotation = rotation * Math.PI / 180;

if (rotation > Math.PI / 2)


rotation = Math.PI / 2;

r.transform = new AffineTransform();


r.transform.translate(x + width / 2, y + height / 2);
r.transform.rotate(rotation);
r.transform.translate(-width / 2, -height / 2);

return r;
}
}

Class: Game

15
package io.flappybird.game;

import io.flappybird.model.PlayGameReq;
import io.flappybird.model.QuestionAsk;
import io.flappybird.model.QuestionsReq;
import io.flappybird.service.SessionManager;
import org.springframework.web.client.RestTemplate;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.io.*;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class Game {

public static final int PIPE_DELAY = 100;

private Boolean paused;

private int pauseDelay;


private int restartDelay;
private int pipeDelay;

private Bird bird;


private ArrayList<Pipe> pipes;
private Keyboard keyboard;
private Pipe pipe;
public int score;
public Boolean gameover;
public Boolean started;
private static Game instance;
private QuestionFrame questionFrame;
private boolean isRunning;

private LocalDateTime questionStartTime;


private static final long QUESTION_TIME_LIMIT_SECONDS =
SessionManager.getInstance().getDurationPerQ();

private LocalDateTime startTime;


private static final long GAME_DURATION_MINUTES =
SessionManager.getInstance().getTotDuration();
private int qCount=0;
int[][] birdPosition = new int[10][2]; // 10 positions in 2D space
QuestionAsk questions=new QuestionAsk();

public Game() {
keyboard = Keyboard.getInstance();
restart();

16
}
public static synchronized Game getInstance() {
if (instance == null) {
instance = new Game();
}
return instance;
}

public void restart() {


paused = false;
started = false;
gameover = false;
qCount=0;
score = 0;
pauseDelay = 0;
restartDelay = 0;
pipeDelay = 0;

bird = new Bird();


pipes = new ArrayList<Pipe>();
pipe=new Pipe("south");
}

public void update() throws Exception {


watchForStart();

if (!started)
return;

watchForPause();
watchForReset();

if (paused)
return;

bird.update();

if (gameover)
return;

movePipes();
checkForCollisions();
}

public ArrayList<Render> getRenders() {


ArrayList<Render> renders = new ArrayList<Render>();
renders.add(new Render(0, 0, "src/main/resources/static/background.png"));
for (Pipe pipe : pipes)
renders.add(pipe.getRender());
renders.add(bird.getRender());
return renders;

17
}

private void watchForStart() throws Exception {


if (!started && keyboard.isDown(KeyEvent.VK_SPACE)) {
started = true;
startTime = LocalDateTime.now();
System.out.println("==================Game-----------------===============");
SessionManager.getInstance().setCurrentQuestionIndex(0);//Start From first Question
SessionManager.getInstance().setCorrectAnswer(0);//SET Correct Answer COUNT =0
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8080/game/startGame";
PlayGameReq playGameReq=new
PlayGameReq(SessionManager.getInstance().getQuizIdS(),
SessionManager.getInstance().getCorrectAnswer(),"Current
Quiz",SessionManager.getInstance().getUserId(),"127.0.01");
System.out.println("playGameReq========"+playGameReq);
String questions = restTemplate.postForObject(url, playGameReq, String.class);
qCount=0;
int hs=findHighScore();
SessionManager.getInstance().setHighestScore(hs);
}
}

private void watchForPause() {


if (pauseDelay > 0)
pauseDelay--;

if (keyboard.isDown(KeyEvent.VK_P) && pauseDelay <= 0) {


paused = !paused;
pauseDelay = 10;
}
}

private void watchForReset() {


if (restartDelay > 0)
restartDelay--;

if (keyboard.isDown(KeyEvent.VK_R) && restartDelay <= 0) {


restart();
restartDelay = 10;
return;
}
}

private void movePipes() {


pipeDelay--;

if (pipeDelay < 0) {
pipeDelay = PIPE_DELAY;
Pipe northPipe = null;
Pipe southPipe = null;

18
// Look for pipes off the screen
for (Pipe pipe : pipes) {
if (pipe.x - pipe.width < 0) {
if (northPipe == null) {
northPipe = pipe;
} else if (southPipe == null) {
southPipe = pipe;
break;
}
}
}

if (northPipe == null) {
Pipe pipe = new Pipe("north");
pipes.add(pipe);
northPipe = pipe;
} else {
northPipe.reset();
}

if (southPipe == null) {
Pipe pipe = new Pipe("south");
pipes.add(pipe);
southPipe = pipe;
} else {
southPipe.reset();
}

northPipe.y = southPipe.y + southPipe.height + 175;


}

for (Pipe pipe : pipes) {


pipe.update();
}
}
public void addHighScore(int score) throws Exception {
RandomAccessFile file = new RandomAccessFile("highscores.dat", "rw");
file.seek(file.length());
file.writeInt(score);
file.close();
}

public void insertScore(int newScore) throws Exception {


RandomAccessFile file = new RandomAccessFile("highscores.dat", "rw");
long length = file.length();
file.seek(length);
file.writeInt(newScore); // Write new score at the end of the file
file.close();
}
public void markHighScoreAsDeleted(int position) throws Exception {
RandomAccessFile file = new RandomAccessFile("highscores.dat", "rw");
file.seek(position);

19
file.writeBoolean(false);
file.close();
}
public int findHighScore() throws Exception {
RandomAccessFile file = new RandomAccessFile("highscores.dat", "r");
int highestScore = Integer.MIN_VALUE; // Start with the lowest possible value
while (file.getFilePointer() < file.length()) {
int score = file.readInt();
if (score > highestScore) {
highestScore = score;
}
}
List<Integer> highScores = new ArrayList<>();
RandomAccessFile file1 = new RandomAccessFile("highscores.dat", "r");

try {
while (file1.getFilePointer() < file1.length()) {
int score = file1.readInt();
highScores.add(score);
}
} finally {
file1.close();
}

System.out.println("highscores.dat File Data>>>"+highScores);


file.close();
return highestScore == Integer.MIN_VALUE ? -1 : highestScore;
}

public int[] mergeScores(int[] localScores, int[] globalScores) {


int[] merged = new int[localScores.length + globalScores.length];
int i = 0, j = 0, k = 0;
while (i < localScores.length && j < globalScores.length) {
if (localScores[i] < globalScores[j]) {
merged[k++] = localScores[i++];
} else {
merged[k++] = globalScores[j++];
}
}
while (i < localScores.length) merged[k++] = localScores[i++];
while (j < globalScores.length) merged[k++] = globalScores[j++];
return merged;
}
public void setBirdPosition(int index, int x, int y) {
birdPosition[index][0] = x;
birdPosition[index][1] = y;
}

private void checkForCollisions() throws Exception {


for (Pipe pipe : pipes) {
if (pipe.collides(bird.x, bird.y, bird.width, bird.height)) {

20
gameover = true;
bird.dead = true;
addHighScore(score);
SessionManager.getInstance().setRecentScore(score);
RestTemplate restTemplate = new RestTemplate();
//
String url = "http://localhost:8080/game/endGame";
PlayGameReq playGameReq=new
PlayGameReq(SessionManager.getInstance().getQuizIdS(),
SessionManager.getInstance().getCorrectAnswer(),"Current
Quiz",SessionManager.getInstance().getUserId(),"127.0.01");
System.out.println("playGameReq========"+playGameReq);
String questions = restTemplate.postForObject(url, playGameReq, String.class);
SessionManager.getInstance().setCurrentQuestionIndex(0);//Start From first Question
SessionManager.getInstance().setCorrectAnswer(0);//SET Correct Answer COUNT =0
} else if (pipe.x == bird.x && pipe.orientation.equalsIgnoreCase("south")) {

if(qCount>9)
{
addHighScore(score);
SessionManager.getInstance().setRecentScore(score);
//Write code to stop from app file if totalQuestion=10 then stopString url =
"http://localhost:8080/game/endGame";
PlayGameReq playGameReq=new
PlayGameReq(SessionManager.getInstance().getQuizIdS(),
SessionManager.getInstance().getCorrectAnswer(),"Current
Quiz",SessionManager.getInstance().getUserId(),"127.0.01");
System.out.println("playGameReq========"+playGameReq);
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8080/game/endGame";
String questions = restTemplate.postForObject(url, playGameReq, String.class);
SessionManager.getInstance().setCurrentQuestionIndex(0);//Start From first Question
SessionManager.getInstance().setCorrectAnswer(0);//SET Correct Answer COUNT =0
SessionManager.getInstance().setGameOpen(false);
JOptionPane.showMessageDialog(null,
"Quiz Completed!",
"Game Over",
JOptionPane.OK_OPTION);
App.frameDispose();
int hs=findHighScore();
SessionManager.getInstance().setHighestScore(hs);
}

score++;

if (score%2==0){
showNextQuestion();
qCount=qCount+1;

}
}
}

21
// Ground + Bird collision
if (bird.y + bird.height > App.HEIGHT - 80) {
gameover = true;
addHighScore(score);
SessionManager.getInstance().setRecentScore(score);
bird.y = App.HEIGHT - 80 - bird.height;
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8080/game/endGame";
PlayGameReq playGameReq=new
PlayGameReq(SessionManager.getInstance().getQuizIdS(),
SessionManager.getInstance().getCorrectAnswer(),"Current
Quiz",SessionManager.getInstance().getUserId(),"127.0.01");
System.out.println("playGameReq========"+playGameReq);
String questions = restTemplate.postForObject(url, playGameReq, String.class);
SessionManager.getInstance().setCurrentQuestionIndex(0);//Start From first Question
SessionManager.getInstance().setCorrectAnswer(0);//SET Correct Answer COUNT =0
}
}
private void showNextQuestion() {
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8080/question/next";
QuestionsReq questions = restTemplate.postForObject(url, score, QuestionsReq.class);
System.out.println(questions.toString());
showQuestion(questions);
}
private boolean hasGameExceededDuration() {
if (startTime == null) {
return false;
}
Duration elapsedTime = Duration.between(startTime, LocalDateTime.now());
return elapsedTime.toMinutes() >= GAME_DURATION_MINUTES;
}
private void showQuestion(QuestionsReq questions) {
paused = true;
// Example question and options
System.out.println(questions.toString());
String question = questions.getQuestionDescription();
String option1 = questions.getOptionA();
String option2 = questions.getOptionB();
String option3 = questions.getOptionC();
String option4 = questions.getOptionD();
String option5 = questions.getOptionE();
String ans = String.valueOf(questions.getAnswer());

// Create QuestionFrame instance


questionFrame = new QuestionFrame(question, option1, option2, option3, option4,option5,ans);

// Set the frame to be visible


questionFrame.setVisible(true);
questionStartTime = LocalDateTime.now();
// Add a window listener to resume game when QuestionFrame is closed

22
questionFrame.addSubmitListener(new QuestionFrame.SubmitListener() {
@Override
public void onSubmit(String selectedOption) {
System.out.println("selectedOption"+selectedOption);
paused = false;
}
});
}
private boolean hasQuestionTimeExpired() {
if (questionStartTime == null) {
return false;
}
Duration elapsedTime = Duration.between(questionStartTime, LocalDateTime.now());
return elapsedTime.getSeconds() >= QUESTION_TIME_LIMIT_SECONDS;
}

Class: GamePanel

package io.flappybird.game;

import javax.swing.*;
import java.awt.*;

public class GamePanel extends JPanel implements Runnable {

private Game game;

public GamePanel() {
this.game = Game.getInstance();
new Thread(this).start();
}

public void update() throws Exception {


game.update();
repaint();
}

protected void paintComponent(Graphics g) {


super.paintComponent(g);

Graphics2D g2D = (Graphics2D) g;


for (Render r : game.getRenders())
if (r.transform != null)
g2D.drawImage(r.image, r.transform, null);
else
g.drawImage(r.image, r.x, r.y, null);

g2D.setColor(Color.BLACK);

23
if (!game.started) {
g2D.setFont(new Font("TimesRoman", Font.PLAIN, 20));
g2D.drawString("Press SPACE to start", 150, 240);

} else {
g2D.setFont(new Font("TimesRoman", Font.PLAIN, 24));
g2D.drawString(Integer.toString(game.score), 10, 465);
}

if (game.gameover) {
g2D.setFont(new Font("TimesRoman", Font.PLAIN, 20));
g2D.drawString("Press R to restart", 150, 240);
}
}

public void run() {


try {
while (true) {
update();
Thread.sleep(25);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Class: Keyboard

package io.flappybird.game;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class Keyboard implements KeyListener {

private static Keyboard instance;

private boolean[] keys;

private Keyboard() {
keys = new boolean[256];
}

public static Keyboard getInstance() {

if (instance == null) {
instance = new Keyboard();
}

return instance;

24
}

public void keyPressed(KeyEvent e) {


if (e.getKeyCode() >= 0 && e.getKeyCode() < keys.length) {
keys[e.getKeyCode()] = true;
}
}

public void keyReleased(KeyEvent e) {


if (e.getKeyCode() >= 0 && e.getKeyCode() < keys.length) {
keys[e.getKeyCode()] = false;
}
}

public void keyTyped(KeyEvent e) {}

public boolean isDown(int key) {

if (key >= 0 && key < keys.length) {


return keys[key];
}

return false;
}
}
Class: Pipe

package io.flappybird.game;
import java.awt.Image;
public class Pipe {

public int x;
public int y;
public int width;
public int height;
public int speed = 3;

public String orientation;

private Image image;

public Pipe(String orientation) {


this.orientation = orientation;
reset();
}

public void reset() {


width = 66;
height = 400;
x = App.WIDTH + 2;

if (orientation.equals("south")) {

25
y = -(int)(Math.random() * 120) - height / 2;
}
}

public void update() {


x -= speed;
}

public boolean collides(int _x, int _y, int _width, int _height) {

int margin = 2;

if (_x + _width - margin > x && _x + margin < x + width) {

if (orientation.equals("south") && _y < y + height) {


return true;
} else if (orientation.equals("north") && _y + _height > y) {
return true;
}
}

return false;
}

public Render getRender() {


Render r = new Render();
r.x = x;
r.y = y;

if (image == null) {
image = Util.loadImage("src/main/resources/static/pipe-" + orientation + ".png");
}
r.image = image;

return r;
}
}

Class: QuestionFrame

package io.flappybird.game;

import io.flappybird.service.SessionManager;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class QuestionFrame extends JFrame {

private JLabel questionLabel;

26
private JRadioButton option1Button;
private JRadioButton option2Button;
private JRadioButton option3Button;
private JRadioButton option4Button;
private JRadioButton option5Button;
private ButtonGroup optionGroup;
private JButton submitButton;

private String correctAnswer;


private String selectedOption;

public interface SubmitListener {


void onSubmit(String selectedOption);
}

private SubmitListener submitListener;

public QuestionFrame(String question, String option1, String option2, String option3, String option4,
String option5,String correctAnswer) {
setTitle("Answer the Question");
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);

this.correctAnswer = correctAnswer;
System.out.println("correctAnswer "+correctAnswer);
initComponents(question, option1, option2, option3, option4,option5);
layoutComponents();
setVisible(true);
}

private void initComponents(String question, String option1, String option2, String option3, String
option4,String option5) {
questionLabel = new JLabel(question);
option1Button = new JRadioButton(option1);
option2Button = new JRadioButton(option2);
option3Button = new JRadioButton(option3);
option4Button = new JRadioButton(option4);
option5Button = new JRadioButton(option5);

optionGroup = new ButtonGroup();


optionGroup.add(option1Button);
optionGroup.add(option2Button);
optionGroup.add(option3Button);
optionGroup.add(option4Button);
optionGroup.add(option5Button);

submitButton = new JButton("Submit");


submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (submitListener != null) {

27
if (option1Button.isSelected()) {
selectedOption = option1Button.getText();
} else if (option2Button.isSelected()) {
selectedOption = option2Button.getText();
} else if (option3Button.isSelected()) {
selectedOption = option3Button.getText();
} else if (option4Button.isSelected()) {
selectedOption = option4Button.getText();
}else if (option5Button.isSelected()) {
selectedOption = option5Button.getText();
}
if (selectedOption == null) {
JOptionPane.showMessageDialog(null, "Please Select Answer");
//submitListener.onSubmit(null); // Notify incorrect answer
return;
}
if (selectedOption.equalsIgnoreCase(correctAnswer)) {
submitListener.onSubmit(selectedOption); // Notify correct answer
int cAnsCount=SessionManager.getInstance().getCorrectAnswer();
cAnsCount=cAnsCount+1;
SessionManager.getInstance().setCorrectAnswer(cAnsCount);//SET Correct Answer
COUNT =0
} else {
JOptionPane.showMessageDialog(null, "Wrong Answer");
submitListener.onSubmit(null); // Notify incorrect answer
}

dispose(); // Close the QuestionFrame after submission


}
}
});
}

private void layoutComponents() {


setLayout(new GridLayout(7, 1));
add(questionLabel);
//questionLabel.setPreferredSize(new Dimension(400, 100));
add(option1Button);
add(option2Button);
add(option3Button);
add(option4Button);
add(option5Button);
add(submitButton);
}

public void addSubmitListener(SubmitListener listener) {


this.submitListener = listener;
}
}

Class: Render

28
package io.flappybird.game;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;

public class Render {


public int x;
public int y;
public Image image;
public AffineTransform transform;

public Render() {
}

public Render(int x, int y, String imagePath) {


Toolkit.getDefaultToolkit().sync();
this.x = x;
this.y = y;
this.image = Util.loadImage(imagePath);
}
}

Class: AchievementsReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

@ToString
@Data
public class AchievementsReq {
private int totalTrophies;
private int totalCertificates;

public AchievementsReq(int totalTrophies, int totalCertificates) {


this.totalTrophies = totalTrophies;
this.totalCertificates = totalCertificates;
}

public int getTotalTrophies() {


return totalTrophies;
}

public void setTotalTrophies(int totalTrophies) {


this.totalTrophies = totalTrophies;
}

public int getTotalCertificates() {


return totalCertificates;

29
}

public void setTotalCertificates(int totalCertificates) {


this.totalCertificates = totalCertificates;
}
}

Class: GenderMasterReq

package io.flappybird.model;

import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;

@ToString
@Data
@Entity
@Table(name = "GenderMaster")
public class GenderMasterReq {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "genderid")
private int genderId;

@Column(name = "gender")
private String gender;
@Column(name = "isactive")
private boolean isActive;

Class: GradeMasterReq

package io.flappybird.model;

import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;

@ToString
@Data
@Entity
@Table(name = "GradeMaster")
public class GradeMasterReq {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "gradeid")
private int gradeId;

30
@Column(name = "grade")
private String grade;

@Column(name = "isactive")
private boolean isActive;

Class: LoginHistoryReq

package io.flappybird.model;
import lombok.Data;
import lombok.ToString;
import java.util.Date;

@ToString
@Data
public class LoginHistoryReq {
private String firstName;
private String loginId;
private String password;
private String userTypeName;
private Date loginDate;
private Date logoutDate;
private double totalDuration;

public LoginHistoryReq(String firstName,String loginId, String password, String userTypeName,


Date loginDate, Date logoutDate, double totalDuration) {
this.firstName = firstName;
this.loginId = loginId;
this.password = password;
this.userTypeName = userTypeName;
this.loginDate = loginDate;
this.logoutDate = logoutDate;
this.totalDuration = totalDuration;

Class: PlayGameReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

@ToString
@Data
public class PlayGameReq {

31
private int quizId;
private int correctAns;
private String quizName;
private int userId;
private String ipAddress;

public int getQuizId() {


return quizId;
}

public void setQuizId(int quizId) {


this.quizId = quizId;
}

public int getCorrectAns() {


return correctAns;
}

public void setCorrectAns(int correctAns) {


this.correctAns = correctAns;
}

public String getQuizName() {


return quizName;
}

public void setQuizName(String quizName) {


this.quizName = quizName;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId = userId;
}

public String getIpAddress() {


return ipAddress;
}

public void setIpAddress(String ipAddress) {


this.ipAddress = ipAddress;
}

public PlayGameReq(int quizId, int correctAns, String quizName, int userId, String ipAddress) {
this.quizId = quizId;
this.correctAns = correctAns;
this.quizName = quizName;
this.userId = userId;
this.ipAddress = ipAddress;

32
}
public PlayGameReq() {
}
}

Class: QuestionAsk

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;
@ToString
@Data
public class QuestionAsk {

private String qName;


private String op1;
private String op2;
private String op3;
private String op4;
private String op5;
private String ans;

public String getqName() {


return qName;
}

public void setqName(String qName) {


this.qName = qName;
}

public String getOp1() {


return op1;
}

public void setOp1(String op1) {


this.op1 = op1;
}

public String getOp2() {


return op2;
}

public void setOp2(String op2) {


this.op2 = op2;
}

public String getOp3() {


return op3;
}

public void setOp3(String op3) {

33
this.op3 = op3;
}

public String getOp4() {


return op4;
}

public void setOp4(String op4) {


this.op4 = op4;
}

public String getOp5() {


return op5;
}

public void setOp5(String op5) {


this.op5 = op5;
}

public String getAns() {


return ans;
}

public void setAns(String ans) {


this.ans = ans;
}

public QuestionAsk() {
}
@Override
public String toString() {
return "QuestionAsk [qName=" + qName + ", op1=" + op1 + ", op2=" + op2 + ", op3=" + op3 + ",
op4=" + op4 +", op5=" + op5 + ", ans=" + ans + "]";
}

Class: QuestionDTOReq

package io.flappybird.model;
import lombok.Data;

@Data
public class QuestionDTOReq {

private int questionId;


public QuestionDTOReq() {
}
}

Class: QuestionsReq

34
package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

import java.util.Date;

@Data
@ToString
public class QuestionsReq {
private int questionId;
private int quizId;
private String questionDescription;
private String questionHint;
private String optionA;
private String optionB;
private String optionC;
private String optionD;
private String optionE;
private String answer;
private int qSno;
private Date transDate;
private Boolean isActive;
private int userId;
public Boolean getActive() {
return isActive;
}
public void setActive(Boolean active) {
isActive = active;
}

public int getQuestionId() {


return questionId;
}

public void setQuestionId(int questionId) {


this.questionId = questionId;
}

public int getQuizId() {


return quizId;
}

public void setQuizId(int quizId) {


this.quizId = quizId;
}

public String getQuestionDescription() {


return questionDescription;
}

public void setQuestionDescription(String questionDescription) {

35
this.questionDescription = questionDescription;
}

public String getQuestionHint() {


return questionHint;
}

public void setQuestionHint(String questionHint) {


this.questionHint = questionHint;
}

public String getOptionA() {


return optionA;
}

public void setOptionA(String optionA) {


this.optionA = optionA;
}

public String getOptionB() {


return optionB;
}

public void setOptionB(String optionB) {


this.optionB = optionB;
}

public String getOptionC() {


return optionC;
}

public void setOptionC(String optionC) {


this.optionC = optionC;
}

public String getOptionD() {


return optionD;
}

public void setOptionD(String optionD) {


this.optionD = optionD;
}

public String getOptionE() {


return optionE;
}

public void setOptionE(String optionE) {


this.optionE = optionE;
}

public String getAnswer() {

36
return answer;
}

public void setAnswer(String answer) {


this.answer = answer;
}

public int getqSno() {


return qSno;
}

public void setqSno(int qSno) {


this.qSno = qSno;
}

public Date getTransDate() {


return transDate;
}

public void setTransDate(Date transDate) {


this.transDate = transDate;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId = userId;
}

public QuestionsReq(int questionId, int quizId, String questionDescription, String questionHint, String
optionA, String optionB, String optionC, String optionD, String optionE, String answer, int qSno, Date
transDate, Boolean isActive, int userId) {
this.questionId = questionId;
this.quizId = quizId;
this.questionDescription = questionDescription;
this.questionHint = questionHint;
this.optionA = optionA;
this.optionB = optionB;
this.optionC = optionC;
this.optionD = optionD;
this.optionE = optionE;
this.answer = answer;
this.qSno = qSno;
this.transDate = transDate;
this.isActive = isActive;
this.userId = userId;
}
public QuestionsReq() {
}
}

37
Class: QuizDDLReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;
@ToString
@Data

public class QuizDDLReq {


private int quizId;
private String quizName;

public QuizDDLReq(int quizId, String quizName) {


this.quizId = quizId;
this.quizName = quizName;
}
}

Class: QuizReq

package io.flappybird.model;
import lombok.Data;
import lombok.ToString;

import java.util.Date;

@ToString
@Data
public class QuizReq {
private int quizId;
private String quizName;
private String teacherName;
private String topicName;
private String levelName;
private int totalQuestions;
private int maxMarks;
private int minMarks;
private int duration;
private boolean isActive;
private String ipAddress;
private Date transDate;
private int userId;

public QuizReq(int quizId, String quizName, String teacherName, String topicName, String
levelName, int totalQuestions, int maxMarks, int minMarks, int duration, boolean isActive, String
ipAddress, Date transDate, int userId) {
this.quizId = quizId;
this.quizName = quizName;
this.teacherName = teacherName;

38
this.topicName = topicName;
this.levelName = levelName;
this.totalQuestions = totalQuestions;
this.maxMarks = maxMarks;
this.minMarks = minMarks;
this.duration = duration;
this.isActive = isActive;
this.ipAddress = ipAddress;
this.transDate = transDate;
this.userId = userId;
}
}

Class: ScoreReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

@ToString
@Data
public class ScoreReq {
private int highestScore;
private int recentScore;

public ScoreReq(int highestScore, int recentScore) {


this.highestScore = highestScore;
this.recentScore = recentScore;
}

public int getHighestScore() {


return highestScore;
}

public void setHighestScore(int highestScore) {


this.highestScore = highestScore;
}

public int getRecentScore() {


return recentScore;
}

public void setRecentScore(int recentScore) {


this.recentScore = recentScore;
}
}
Class: StudentDDLReq

package io.flappybird.model;

import jakarta.persistence.Column;

39
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

@ToString
@Data

public class StudentDDLReq {


private int studentId;
private String studentName;

public StudentDDLReq(int studentId, String studentName) {


this.studentId = studentId;
this.studentName = studentName;
}
}

Class: StudentDTO

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

import java.time.LocalDateTime;

@Data
@ToString
public class StudentDTO {
private Integer studentId;
private String surname;
private String firstName;
private Integer gradeId;
private String grade;
private String emailId;
private Integer age;
private Integer genderId;
private String gender;
private String mobileNo;
private Integer totalTrophies;
private Integer totalCertificates;
private String ipAddress;
private LocalDateTime transDate;
private Boolean isActive;
private Integer userId;

public StudentDTO(Integer studentId, String surname, String firstName, Integer gradeId, String
grade, String emailId, Integer age,
Integer genderId,String gender, String mobileNo, Integer totalTrophies, Integer
totalCertificates,
String ipAddress, LocalDateTime transDate, Boolean isActive, Integer userId) {
this.studentId = studentId;

40
this.surname = surname;
this.firstName = firstName;
this.gradeId = gradeId;
this.grade = grade;
this.emailId = emailId;
this.age = age;
this.genderId = genderId;
this.gender = gender;
this.mobileNo = mobileNo;
this.totalTrophies = totalTrophies;
this.totalCertificates = totalCertificates;
this.ipAddress = ipAddress;
this.transDate = transDate;
this.isActive = isActive;
this.userId = userId;
}

Class: StudentReq

package io.flappybird.model;
import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;

import java.time.LocalDate;

@ToString
@Data
@Entity
public class StudentReq {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

@Column(name = "studentid")
private int studentId;
@Column(name = "surname")
private String surName;
@Column(name = "firstname")
private String firstName;
@Column(name = "age")
private int age;

@Column(name = "genderid")
private int genderId;
@Column(name = "gender")
private String gender;

@Column(name = "gradeid")
private int gradeId;

41
@Column(name = "grade")
private String grade;

@Column(name = "emailid")
private String emailId;
@Column(name = "mobileno")
private String mobileNo;
@Column(name = "totaltrophies")
private int totalTrophies;
@Column(name = "totalcertificates")
private int totalCertificates;
// private boolean status;
@Column(name = "ipaddress")
private String ipAddress;
@Column(name = "transdate")
private LocalDate transDate;
@Column(name = "isactive")
private Boolean isActive;
@Column(name = "userid",nullable = true)
private Integer userId;

public Boolean getActive() {


return isActive;
}

public void setActive(Boolean active) {


isActive = active;
}

Class: TeacherReq

package io.flappybird.model;

import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;
import java.time.LocalDate;
@ToString
@Data
@Entity
public class TeacherReq {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "teacherid")
private int teacherId;
@Column(name = "surname")
private String surName;
@Column(name = "firstname")
private String firstName;
@Column(name = "age")

42
private int age;

@Column(name = "genderid")
private int genderId;
@Column(name = "gender")
private String gender;
@Column(name = "emailid")
private String emailId;
@Column(name = "mobileno")
private String mobileNo;
@Column(name = "ipaddress")
private String ipAddress;
@Column(name = "transdate")
private LocalDate transDate;
@Column(name = "isactive")
private Boolean isActive;
@Column(name = "userid",nullable = true)
private Integer userId;

public Boolean getActive() {


return isActive;
}

public void setActive(Boolean active) {


isActive = active;
}
}

Class: TopicDDLReq

package io.flappybird.model;

import jakarta.persistence.*;
import lombok.Data;
import lombok.ToString;
import java.time.LocalDate;
@ToString
@Data
@Entity
public class TeacherReq {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "teacherid")
private int teacherId;
@Column(name = "surname")
private String surName;
@Column(name = "firstname")
private String firstName;
@Column(name = "age")
private int age;

@Column(name = "genderid")

43
private int genderId;
@Column(name = "gender")
private String gender;
@Column(name = "emailid")
private String emailId;
@Column(name = "mobileno")
private String mobileNo;
@Column(name = "ipaddress")
private String ipAddress;
@Column(name = "transdate")
private LocalDate transDate;
@Column(name = "isactive")
private Boolean isActive;
@Column(name = "userid",nullable = true)
private Integer userId;

public Boolean getActive() {


return isActive;
}

public void setActive(Boolean active) {


isActive = active;
}
}

Class: TopicReq

package io.flappybird.model;
import lombok.Data;
@Data
public class TopicReq {
private int topicId;
private String topicName;
private int isActive;
private int userId;

public int getTopicId() {


return topicId;
}

public void setTopicId(int topicId) {


this.topicId = topicId;
}

public String getTopicName() {


return topicName;
}

public void setTopicName(String topicName) {


this.topicName = topicName;
}

44
public int getIsActive() {
return isActive;
}

public void setIsActive(int isActive) {


this.isActive = isActive;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId = userId;
}
}

Class: TopicStatusReq

private Boolean isActive;


@Column(name = "userid",nullable = true)
private Integer userId;
public Boolean getActive() {
return isActive;
}
public void setActive(Boolean active) {
isActive = active;
}
}
Class: TopicReq

package io.flappybird.model;
import lombok.Data;
@Data
public class TopicReq {
private int topicId;
private String topicName;
private int isActive;
private int userId;
public int getTopicId() {
return topicId;
}
public void setTopicId(int topicId) {
this.topicId = topicId;
}
public String getTopicName() {
return topicName;

45
}
public void setTopicName(String topicName) {
this.topicName = topicName;
}
public int getIsActive() {
return isActive;
}
public void setIsActive(int isActive) {
this.isActive = isActive;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
}
Class: TopicStatusReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

import java.util.Date;

@ToString
@Data
public class TopicStatusReq {
private String topicName;
private String quizName;
private String teacherName;
private int totalQuestions;
private int maxMarks;
private int minMarks;
private int duration;
private Date playDate;
private Date startTime;
private Date endTime;
private String accuracy;
private String result;

public TopicStatusReq(String topicName,String quizName, String teacherName, int totalQuestions,


int maxMarks, int minMarks, int duration, Date playDate, Date startTime, Date endTime, String
accuracy, String result) {
this.topicName = topicName;
this.quizName = quizName;
this.teacherName = teacherName;
this.totalQuestions = totalQuestions;

46
this.maxMarks = maxMarks;
this.minMarks = minMarks;
this.duration = duration;
this.playDate = playDate;
this.startTime = startTime;
this.endTime = endTime;
this.accuracy = accuracy;
this.result = result;
}
}

Class: UpdateStudentProfileReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

import java.util.Date;

@ToString
@Data
public class UpdateStudentProfileReq {
private String surname;
private String firstName;
private int genderId;
private String gender;
private String emailId;
private String mobile;
private int age;
private int gradeId;
private String grade;
private int userId;

public UpdateStudentProfileReq() {

public UpdateStudentProfileReq(String surname, String firstName, int genderId, String gender,


String emailId, String mobile, int age, int gradeId, String grade, int userId) {
this.surname = surname;
this.firstName = firstName;
this.genderId = genderId;
this.gender = gender;
this.emailId = emailId;
this.mobile = mobile;
this.age = age;
this.gradeId = gradeId;
this.grade = grade;
this.userId = userId;
}

47
public String getSurname() {
return surname;
}

public void setSurname(String surname) {


this.surname = surname;
}

public String getFirstName() {


return firstName;
}

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public int getGenderId() {


return genderId;
}

public void setGenderId(int genderId) {


this.genderId = genderId;
}

public String getGender() {


return gender;
}

public void setGender(String gender) {


this.gender = gender;
}

public String getEmailId() {


return emailId;
}

public void setEmailId(String emailId) {


this.emailId = emailId;
}

public String getMobile() {


return mobile;
}

public void setMobile(String mobile) {


this.mobile = mobile;
}

public int getAge() {


return age;
}

48
public void setAge(int age) {
this.age = age;
}

public int getGradeId() {


return gradeId;
}

public void setGradeId(int gradeId) {


this.gradeId = gradeId;
}

public String getGrade() {


return grade;
}

public void setGrade(String grade) {


this.grade = grade;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId = userId;
}
}

Class: UpdateTeacherProfileReq

package io.flappybird.model;

import lombok.Data;
import lombok.ToString;

import java.util.Date;

@ToString
@Data
public class UpdateTeacherProfileReq {
private String surname;
private String firstName;
private int genderId;
private String gender;
private String emailId;
private String mobile;

private int age;


private int userId;

public UpdateTeacherProfileReq() {

49
}

public UpdateTeacherProfileReq(String surname, String firstName, int genderId, String gender,


String emailId, String mobile, int age, int userId) {
this.surname = surname;
this.firstName = firstName;
this.genderId = genderId;
this.gender = gender;
this.emailId = emailId;
this.mobile = mobile;
this.age = age;
this.userId = userId;
}

public String getSurname() {


return surname;
}

public void setSurname(String surname) {


this.surname = surname;
}

public String getFirstName() {


return firstName;
}

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public int getGenderId() {


return genderId;
}

public void setGenderId(int genderId) {


this.genderId = genderId;
}

public String getGender() {


return gender;
}

public void setGender(String gender) {


this.gender = gender;
}

public String getEmailId() {


return emailId;
}

public void setEmailId(String emailId) {

50
this.emailId = emailId;
}

public String getMobile() {


return mobile;
}

public void setMobile(String mobile) {


this.mobile = mobile;
}

public int getAge() {


return age;
}

public void setAge(int age) {


this.age = age;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId = userId;
}
}

Class: UserDetailsDTOReq

package io.flappybird.model;

public class UserDetailsDTOReq {


private String loginId;
private int userTypeId;
private String firstName;
public UserDetailsDTOReq(String loginId, String firstName, int userTypeId) {
this.loginId = loginId;
this.firstName = firstName;
this.userTypeId=userTypeId;
}

public String getLoginId() {


return loginId;
}

public String getFirstName() {


return firstName;
}

public int getUserTypeId() {


return userTypeId;

51
}

public void setUserTypeId(int userTypeId) {


this.userTypeId = userTypeId;
}
}

Class: UserReq

package io.flappybird.model;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class UserReq {

private int userId;


@NotEmpty(message = "User Type is required")
private int userTypeId;

@NotEmpty(message = "Surname is required")


private String surname;

@NotEmpty(message = "First Name is required")


private String firstName;

@NotEmpty(message = "Age is required")


private int age;

@NotEmpty(message = "Gender is required")


private String gender;

@NotEmpty(message = "Grade is required")


private String grade;

@NotEmpty(message = "Email is required")


@Email(message = "Email should be valid")
private String email;

@NotEmpty(message = "Username is required")


private String username;

@NotEmpty(message = "Password is required")


@Size(min = 8, message = "Password must be at least 8 characters long")

52
@Pattern(regexp = "^(?=.*[0-9])(?=.*[!@#$%^&*]).{8,}$", message = "Password must contain at
least one numeric and one special character")
private String password;

private String confirmPassword;

private String school;

// Getters and Setters

// Custom method to check if passwords match


public boolean isPasswordsMatching() {
return password != null && password.equals(confirmPassword);
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId=userId;
}
public int getUserTypeId() {
return userTypeId;
}

public void setUserTypeId(int userTypeId) {


this.userTypeId=userTypeId;
}

public String getSurname() {


return surname;
}

public void setSurname(String surname) {


this.surname = surname;
}

public String getFirstName() {


return firstName;
}

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public int getAge() {


return age;
}

public void setAge(int age) {


this.age = age;

53
}

public String getGender() {


return gender;
}

public void setGender(String gender) {


this.gender = gender;
}

public String getGrade() {


return grade;
}

public void setGrade(String grade) {


this.grade = grade;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public String getUsername() {


return username;
}

public void setUsername(String username) {


this.username = username;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


this.password = password;
}

public String getConfirmPassword() {


return confirmPassword;
}

public void setConfirmPassword(String confirmPassword) {


this.confirmPassword = confirmPassword;
}

public String getSchool() {


return school;

54
}

public void setSchool(String school) {


this.school = school;
}
}

Class: UserSignUpReq

package io.flappybird.model;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class UserSignUpReq {
@NotEmpty(message = "User Type is required")
private int userTypeId;

@NotEmpty(message = "Surname is required")


private String surname;

@NotEmpty(message = "First Name is required")


private String firstName;
@NotEmpty(message = "Gender is required")
private int genderId;
@NotEmpty(message = "Mobile is required")
@Size(min = 10,max=10, message = "Mobile must be a 10 digits long")
private String mobile;
@NotEmpty(message = "Email is required")
@Email(message = "Email should be valid")
private String email;
@NotEmpty(message = "Password is required")
@Size(min = 8, message = "Password must be at least 8 characters long")
@Pattern(regexp = "^(?=.*[0-9])(?=.*[!@#$%^&*]).{8,}$", message = "Password must contain at
least one numeric and one special character")
private String password;
private String confirmPassword;

public int getUserTypeId() {


return userTypeId;
}

public void setUserTypeId(int userTypeId) {


this.userTypeId = userTypeId;
}

55
public String getSurname() {
return surname;
}

public void setSurname(String surname) {


this.surname = surname;
}

public String getFirstName() {


return firstName;
}

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public int getGenderId() {


return genderId;
}

public void setGenderId(int genderId) {


this.genderId = genderId;
}

public String getMobile() {


return mobile;
}

public void setMobile(String mobile) {


this.mobile = mobile;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


this.password = password;
}

public String getConfirmPassword() {


return confirmPassword;
}

56
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}

public boolean isPasswordsMatching() {


return password != null && password.equals(confirmPassword);
}

Class: MD5HashUtil

package io.flappybird.service;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5HashUtil {


public static String md5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : messageDigest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

public static void main(String[] args) {


String password = "Test@123";
String hashedPassword = md5(password);
System.out.println("MD5 Hashed Password: " + hashedPassword);
}
}

Class: PlayGameService

package io.flappybird.service;

import io.flappybird.model.PlayGameReq;
import io.flappybird.model.ScoreReq;
import io.flappybird.repo.PlayGameRepo;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

57
@Service

public class PlayGameService {


@Autowired
private PlayGameRepo playGameRepo;

@Transactional
public String startGame(PlayGameReq playGameReq) {
String result =
playGameRepo.startGame("INS",playGameReq.getQuizId(),playGameReq.getCorrectAns(),
SessionManager.getInstance().getUserId(), SessionManager.getInstance().getIp());
return result;
}
@Transactional
public String endGame(PlayGameReq playGameReq) {
String result =
playGameRepo.endGame("UPD",playGameReq.getQuizId(),playGameReq.getCorrectAns(),
SessionManager.getInstance().getUserId(), SessionManager.getInstance().getIp());
return result;
}
@Transactional
public ScoreReq bindScore() {
ScoreReq scoreReq = null;
int highestScore =SessionManager.getInstance().getHighestScore();
int recentScore =SessionManager.getInstance().getRecentScore();
scoreReq = new ScoreReq(highestScore,recentScore);
return scoreReq;
}

Class: QuestionFrame

package io.flappybird.service;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class QuestionFrame extends JFrame {

private JLabel questionLabel;


private JRadioButton option1Button;
private JRadioButton option2Button;
private JRadioButton option3Button;
private JRadioButton option4Button;
private ButtonGroup optionGroup;
private JButton submitButton;

private String correctAnswer;

58
private String selectedOption;

public interface SubmitListener {


void onSubmit(String selectedOption);
}

private SubmitListener submitListener;

public QuestionFrame(String question, String option1, String option2, String option3, String option4,
String correctAnswer) {
setTitle("Answer the Question");
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);

this.correctAnswer = correctAnswer;

initComponents(question, option1, option2, option3, option4);


layoutComponents();

setVisible(true);
}

private void initComponents(String question, String option1, String option2, String option3, String
option4) {
questionLabel = new JLabel(question);
option1Button = new JRadioButton(option1);
option2Button = new JRadioButton(option2);
option3Button = new JRadioButton(option3);
option4Button = new JRadioButton(option4);

optionGroup = new ButtonGroup();


optionGroup.add(option1Button);
optionGroup.add(option2Button);
optionGroup.add(option3Button);
optionGroup.add(option4Button);

submitButton = new JButton("Submit");


submitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (submitListener != null) {
if (option1Button.isSelected()) {
selectedOption = option1Button.getText();
} else if (option2Button.isSelected()) {
selectedOption = option2Button.getText();
} else if (option3Button.isSelected()) {
selectedOption = option3Button.getText();
} else if (option4Button.isSelected()) {
selectedOption = option4Button.getText();
}

59
if (selectedOption.equalsIgnoreCase(correctAnswer)) {
submitListener.onSubmit(selectedOption); // Notify correct answer
} else {
JOptionPane.showMessageDialog(null, "Answer is incorrect. Game over!");
submitListener.onSubmit(null); // Notify incorrect answer
}

dispose(); // Close the QuestionFrame after submission


}
}
});
}

private void layoutComponents() {


setLayout(new GridLayout(6, 1));
add(questionLabel);
add(option1Button);
add(option2Button);
add(option3Button);
add(option4Button);
add(submitButton);
}

public void addSubmitListener(SubmitListener listener) {


this.submitListener = listener;
}
}

Class: QuestionService

package io.flappybird.service;
import io.flappybird.model.*;
import io.flappybird.repo.QuestionRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service
public class QuestionService {

private final QuestionRepo questionRepo;

@Autowired(required = true)
public QuestionService(QuestionRepo questionRepo) {
this.questionRepo = questionRepo;
}

@Transactional

60
public List<QuestionReq> bindQuestionInfo(String mode,int userId,int quizId)
{
List<?> result =
questionRepo.bindQuestionInfo(mode,quizId,0,null,null,null,null,null,null,null,null,true,SessionManager
.getInstance().getIp(),userId);
List<QuestionReq> questionList = new ArrayList<>();

for (Object obj : result) {


if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 12) {
int questionId = (int) row[0];
int quizIdN = (int) row[1];
String questionDescription = (String) row[2];
String questionHint = (String) row[3];
String optionA = (String) row[4];
String optionB = (String) row[5];
String optionC = (String) row[6];
String optionD = (String) row[7];
String optionE = (String) row[8];
char answer = (char) row[9];
Date transDate = (Date) row[10];
boolean isActive = (boolean) row[11];
int userIdN = (int) row[12];

QuestionReq questionReq = new QuestionReq(questionId,quizIdN, questionDescription,


questionHint, optionA, optionB,
optionC, optionD, optionE, answer,transDate,isActive, userIdN);
questionList.add(questionReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return questionList;
}
@Transactional
public List<QuestionsReq> bindQuestionsInfo(String mode,int userId,int quizId)
{
List<?> quizResult =
questionRepo.getQuizInfo("MST",quizId,0,null,null,null,null,null,null,null,null,true,SessionManager.getI
nstance().getIp(),userId);
for (Object obj : quizResult) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 3) {
SessionManager.getInstance().setTotQ(0);
SessionManager.getInstance().setDurationPerQ(0);
SessionManager.getInstance().setTotDuration(0);

61
SessionManager.getInstance().setTotQ((int) row[0]);
SessionManager.getInstance().setDurationPerQ((int) row[1]);
SessionManager.getInstance().setTotDuration((int) row[2]);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}

List<?> result =
questionRepo.bindQuestionsInfo(mode,quizId,0,null,null,null,null,null,null,null,null,true,SessionManag
er.getInstance().getIp(),userId);
List<QuestionsReq> questionList = new ArrayList<>();

for (Object obj : result) {


if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 13) {
int questionId = (int) row[0];
int quizIdN = (int) row[1];
String questionDescription = (String) row[2];
String questionHint = (String) row[3];
String optionA = (String) row[4];
String optionB = (String) row[5];
String optionC = (String) row[6];
String optionD = (String) row[7];
String optionE = (String) row[8];
String answer = (String) row[9];
int qSno = (int) row[10];
Date transDate = (Date) row[11];
boolean isActive = (boolean) row[12];
int userIdN = (int) row[13];

QuestionsReq questionReq = new QuestionsReq(questionId,quizIdN,


questionDescription, questionHint, optionA, optionB,
optionC, optionD, optionE, answer,qSno,transDate,isActive, userIdN);
questionList.add(questionReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return questionList;
}

62
@Transactional
public List<QuizDDLReq> bindQuizList(String Mode){
List<?> result=questionRepo.bindQuizList(Mode);
List<QuizDDLReq> quizList = new ArrayList<>();
for (Object obj : result) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 1) {
int quizId = (int) row[0];
String quizName = (String) row[1];

QuizDDLReq quizDDLReq = new QuizDDLReq(quizId, quizName);


quizList.add(quizDDLReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return quizList;
}
}

Class: QuizService

package io.flappybird.service;
import io.flappybird.model.QuizDDLReq;
import io.flappybird.model.QuizReq;
import io.flappybird.model.TopicDDLReq;
import io.flappybird.repo.QuizRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service
public class QuizService {
@Autowired
private QuizRepo quizRepo;
@Transactional
public List<TopicDDLReq> bindTopicList(String Mode){
List<?> result=quizRepo.bindTopicList(Mode);
List<TopicDDLReq> topicList = new ArrayList<>();
for (Object obj : result) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;

63
if (row.length >= 1) {
int topicId = (int) row[0];
String topicName = (String) row[1];
TopicDDLReq topicDDLReq = new TopicDDLReq(topicId, topicName);
topicList.add(topicDDLReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
System.out.println(topicList.toString());
return topicList;
}
@Transactional
public List<QuizDDLReq> getQuizListByTopics(String mode,int topicId) {
List<?>
result=quizRepo.getQuizListByTopics(mode,0,null,0,topicId,0,0,true,SessionManager.getInstance().ge
tIp(),1);
List<QuizDDLReq> quizList = new ArrayList<>();
for (Object obj : result) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 1) {
int quizId = (int) row[0];
String quizName = (String) row[1];

QuizDDLReq quizDDLReq = new QuizDDLReq(quizId, quizName);


quizList.add(quizDDLReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
System.out.println(quizList.toString());
return quizList;

@Transactional
public List<QuizReq> bindQuizInfo(String Mode){

List<?> result = quizRepo.bindQuizInfo(Mode);


List<QuizReq> quizList = new ArrayList<>();

for (Object obj : result) {

64
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 12) {
int quizId = (int) row[0];
String quizName = (String) row[1];
String teacherName = (String) row[2];
String topicName = (String) row[3];
String levelName = (String) row[4];
int totalQuestions = (int) row[5];
int maxMarks = (int) row[6];
int minMarks = (int) row[7];
int duration = (int) row[8];
boolean isActive = (boolean) row[9];
String ipAddress = (String) row[10];
Date transDate = (Date) row[11];
int userId = (int) row[12];

QuizReq quizReq = new QuizReq(quizId, quizName, teacherName, topicName,


levelName,
totalQuestions, maxMarks, minMarks, duration,
isActive, ipAddress, transDate, userId);
quizList.add(quizReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return quizList;

}
}

Class: SessionManager

package io.flappybird.service;

import io.flappybird.model.QuestionsReq;

import java.util.List;

public class SessionManager {


private static SessionManager instance;
private int userId;
private String loginId;
private int userTypeId;
private String username;
private boolean gameOpen;
private List<QuestionsReq> questions;
private String ip;

65
private int quizIdS=0;
private int totQ=0;
private int durationPerQ=0;
private int totDuration=0;

private int currentQuestionIndex=0;


private int correctAnswer=0; //Correct Question Count
private int recentScore=0;
private int highestScore=0;

private SessionManager() {

public static SessionManager getInstance() {


if (instance == null) {
instance = new SessionManager();
}
return instance;
}

public String getIp() {


return ip;
}

public void setIp(String ip) {


this.ip = ip;
}

public int getUserId() {


return userId;
}

public void setUserId(int userId) {


this.userId = userId;
}
public String getLoginId() {
return loginId;
}

public void setLoginId(String loginId) {


this.loginId = loginId;
}
public int getUserTypeId() {
return userTypeId;
}

public void setUserTypeId(int userTypeId) {


this.userTypeId = userTypeId;
}

66
public void setUsername(String username) {
this.username = username;
}

public String getUsername() {


return username;
}

public boolean isGameOpen() {


return gameOpen;
}

public void setGameOpen(boolean gameOpen) {


this.gameOpen = gameOpen;
}

public List<QuestionsReq> getQuestions() {


return questions;
}

public void setQuestions(List<QuestionsReq> questions) {


this.questions = questions;
}

public int getQuizIdS() {


return quizIdS;
}

public void setQuizIdS(int quizIdS) {


this.quizIdS = quizIdS;
}

public int getTotQ() {


return totQ;
}

public void setTotQ(int totQ) {


this.totQ = totQ;
}

public int getDurationPerQ() {


return durationPerQ;
}

public void setDurationPerQ(int durationPerQ) {


this.durationPerQ = durationPerQ;
}

public int getTotDuration() {


return totDuration;
}

67
public void setTotDuration(int totDuration) {
this.totDuration = totDuration;
}

public int getCurrentQuestionIndex() {


return currentQuestionIndex;
}

public void setCurrentQuestionIndex(int currentQuestionIndex) {


this.currentQuestionIndex = currentQuestionIndex;
}

public int getCorrectAnswer() {


return correctAnswer;
}

public void setCorrectAnswer(int correctAnswer) {


this.correctAnswer = correctAnswer;
}

public int getRecentScore() {


return recentScore;
}

public void setRecentScore(int recentScore) {


this.recentScore = recentScore;
}

public int getHighestScore() {


return highestScore;
}

public void setHighestScore(int highestScore) {


this.highestScore = highestScore;
}

public void clearSession() {


this.userId = 0;
this.loginId = null;
this.userTypeId = 0;
this.username = null;
this.gameOpen=false;
this.questions=null;
this.quizIdS=0;
this.totQ=0;
this.durationPerQ=0;
this.totDuration=0;
this.currentQuestionIndex=0;
this.correctAnswer=0;//Correct Question Count
this.recentScore=0;
this.highestScore=0;

68
this.ip=null;

}
}

Class: StudentService

package io.flappybird.service;

import io.flappybird.model.*;
import io.flappybird.repo.GenderMasterRepo;
import io.flappybird.repo.GradeMasterRepo;
import io.flappybird.repo.StudentRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
public class StudentService {

@Autowired
private StudentRepo studentRepo;

@Autowired
private GradeMasterRepo gradeMasterRepo;
@Autowired
private GenderMasterRepo genderMasterRepo;
@Transactional
public List<StudentDDLReq> bindStudentList(String Mode){
List<?> result=studentRepo.bindStudentList(Mode);
List<StudentDDLReq> studentDDLReqList = new ArrayList<>();
for (Object obj : result) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 1) {
int studentId = (int) row[0];
String studenName = (String) row[1];
StudentDDLReq studentDDLReqs = new StudentDDLReq(studentId, studenName);
studentDDLReqList.add(studentDDLReqs);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
System.out.println(studentDDLReqList.toString());
return studentDDLReqList;

69
}
@Transactional
public UpdateStudentProfileReq getStudentByUserId(int userId) {
List<?> result = studentRepo.getStudentByUserId("GET",
0,"","","",1,1,1,"","",0,0,true,SessionManager.getInstance().getIp(), userId);
UpdateStudentProfileReq updateStudentProfileReq=null;
for (Object obj : result) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 10) {
String surname = (String) row[0];
String firstName = (String) row[1];
int GenderId = (int) row[2];
String gender = (String) row[3];
String emailId = (String) row[4];
String mobile = (String) row[5];
int age = (int) row[6];
int gradeId = (int) row[7];
String grade = (String) row[8];
int retrievedUserId = (int) row[9];
updateStudentProfileReq = new UpdateStudentProfileReq(surname, firstName, GenderId,
gender,emailId,mobile, age,gradeId, grade,retrievedUserId);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return updateStudentProfileReq;
}
@Transactional
public String updateStudentProfile(UpdateStudentProfileReq updateStudentProfileReq){
String strResult=
studentRepo.updateStudentProfile("UPD",0,updateStudentProfileReq.getSurname(),updateStudentPr
ofileReq.getFirstName(),"",updateStudentProfileReq.getAge(),Integer.parseInt(updateStudentProfileR
eq.getGender()),Integer.parseInt(updateStudentProfileReq.getGrade()),updateStudentProfileReq.getE
mailId(),updateStudentProfileReq.getMobile(),0,0,true,SessionManager.getInstance().getIp(),
SessionManager.getInstance().getUserId());
return strResult;
}
@Transactional
public AchievementsReq bindAchievements(String mode,int userId) {
List<?> result = studentRepo.bindAchievements(mode,0,"","","",1,1,1,"","",1,1,true,"", userId);
AchievementsReq achievementsReq = null;

for (Object obj : result) {


if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 2) {
int totalTrophies = (int) row[0];

70
int totalCertificates = (int) row[1];
achievementsReq = new AchievementsReq(totalTrophies, totalCertificates);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return achievementsReq;
}
@Transactional
public StudentReq getStudentId(String mode, int studentId) {
StudentReq students=studentRepo.getStudentId(mode,studentId,"","","",1,1,1,"","",1,1,true,"",2);
return students; // or throw an exception if preferred
}
@Transactional
public List<StudentReq> bindStudentInfo(String mode){

List<StudentReq> students=studentRepo.bindStudentInfo(mode);
return students;
}

@Transactional
public List<GradeMasterReq> bindDdlGrade(String Mode){
List<GradeMasterReq> gradeMasters=gradeMasterRepo.bindDdlGrade(Mode);
return gradeMasters;
}
@Transactional
public List<GenderMasterReq> bindDdlGender(String Mode){
List<GenderMasterReq> genderMasters=genderMasterRepo.bindDdlGender(Mode);
return genderMasters;
}
@Transactional
public String deleteStudendInfo(String mode, Integer studentId){
String strResult= studentRepo.deleteStudentInfo(mode,studentId,"","","",1,1,1,"","",1,1,true,"",2);
return strResult;
}
}

Class: TeacherService

package io.flappybird.service;

import io.flappybird.model.UpdateTeacherProfileReq;
import io.flappybird.repo.TeacherRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

71
import java.util.List;
@Service
public class TeacherService {
@Autowired
private TeacherRepo teacherRepo;
@Transactional
public UpdateTeacherProfileReq getTeacherByUserId(int userId) {
List<?> result = teacherRepo.getTeacherByUserId("GET",
0,"","","",1,1,"","",true,SessionManager.getInstance().getIp(),userId);
UpdateTeacherProfileReq updateTeacherProfileReq=null;
for (Object obj : result) {
if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 8) {
String surname = (String) row[0];
String firstName = (String) row[1];
int genderId = (int) row[2];
String gender = (String) row[3];
String emailId = (String) row[4];
String mobile = (String) row[5];
int age = (int) row[6];
int retrievedUserId = (int) row[7];
updateTeacherProfileReq = new UpdateTeacherProfileReq(surname, firstName, genderId,
gender,emailId,mobile, age,retrievedUserId);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return updateTeacherProfileReq;
}

@Transactional
public String updateTeacherProfile(UpdateTeacherProfileReq updateTeacherProfileReq){
String strResult=
teacherRepo.updateTeacherProfile("UPD",0,updateTeacherProfileReq.getSurname(),updateTeacherP
rofileReq.getFirstName(),"",updateTeacherProfileReq.getAge(),Integer.parseInt(updateTeacherProfile
Req.getGender()),updateTeacherProfileReq.getEmailId(),updateTeacherProfileReq.getMobile(),true,S
essionManager.getInstance().getIp(), SessionManager.getInstance().getUserId());
System.out.println(strResult);
return strResult;
}
}

Class: TopicService

package io.flappybird.service;
import io.flappybird.model.*;

72
import io.flappybird.repo.TopicRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Service
public class TopicService {
@Autowired
private TopicRepo topicRepo;

@Transactional
public List<TopicStatusReq> topicsStatus(String mode, int userId) {
List<?> result = topicRepo.topicsStatus(mode,0,null,true,userId);
List<TopicStatusReq> topicStatusReqList = new ArrayList<>();

for (Object obj : result) {


if (obj instanceof Object[]) {
Object[] row = (Object[]) obj;
if (row.length >= 12) {
String topicName = (String) row[0];
String quizName = (String) row[1];
String teacherName = (String) row[2];
int totalQuestions = (int) row[3];
int maxMarks = (int) row[4];
int minMarks = (int) row[5];
int duration = (int) row[6];
Date playDate = (Date) row[7];
Date startTime = (Date) row[8];
Date endTime = (Date) row[9];
String accuracy = (String) row[10];
String fresult = (String) row[11];

TopicStatusReq topicStatusReq = new TopicStatusReq(topicName, quizName,


teacherName, totalQuestions, maxMarks,
minMarks, duration,playDate, startTime, endTime, accuracy,fresult);
topicStatusReqList.add(topicStatusReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + obj.getClass());
}
}
return topicStatusReqList;
}

73
@Transactional
public List<TopicReq> getTopicsList(String mode) {
return topicRepo.getTopicsList(mode);
}
@Transactional
public List<TopicReq> getAllTopics() {

return null;//topicRepo.getAllTopics();
}

public String addTopic(String topicName, Integer userId) {

return null;//return topicRepo.addTopic(topicName, userId);


}

public String updateTopic(Integer topicId, String topicName, Integer isActive) {


return null;//return topicRepo.updateTopic(topicId, topicName, isActive);
}

public String deactivateTopic(Integer topicId) {

return null;//return topicRepo.deactivateTopic(topicId);


}
}

Class: UserService

package io.flappybird.service;

import io.flappybird.model.LoginHistoryReq;
import io.flappybird.model.UserReq;
import io.flappybird.model.UserSignUpReq;
import io.flappybird.repo.UserRepo;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
public class UserService {

@Autowired
private UserRepo userRepo;

//@Transactional
public String signUpUser(UserSignUpReq user) {
MD5HashUtil md5HashUtil = new MD5HashUtil();

74
String result =
userRepo.signUpUser("REG",user.getUserTypeId(),user.getSurname(),user.getFirstName(),user.getG
enderId(),user.getMobile(), user.getEmail(),md5HashUtil.md5(user.getPassword()),
SessionManager.getInstance().getIp());
return result;
}
@Transactional
public String loginUser(UserReq user) {
MD5HashUtil md5HashUtil = new MD5HashUtil();
String loginResult =userRepo.loginUser("LOG",user.getUserId(),user.getUserTypeId(),
user.getEmail().trim(), md5HashUtil.md5(user.getPassword()), SessionManager.getInstance().getIp());
if(loginResult.equals("SUCCESS")) {
int uid=userRepo.getLoginUserId("UID",user.getUserId(),user.getUserTypeId(),
user.getEmail().trim(), user.getPassword(), SessionManager.getInstance().getIp());
String userName=userRepo.getLoginUserName("LUN",user.getUserId(),user.getUserTypeId(),
user.getEmail().trim(), user.getPassword(), SessionManager.getInstance().getIp());
SessionManager.getInstance().setUserId(uid);
SessionManager.getInstance().setUsername(userName);
SessionManager.getInstance().setLoginId(user.getEmail().trim());
SessionManager.getInstance().setUserTypeId(user.getUserTypeId());
}
return loginResult;
}

@Transactional
public String logOutUser(UserReq user) {
String result = userRepo.logOutUser("OUT",user.getUserId(),user.getUserTypeId(),
user.getEmail(), user.getPassword(), SessionManager.getInstance().getIp());
return result; // Will return 'Success!' or appropriate error message
}
@Transactional
public String changePassword(UserReq user) {
MD5HashUtil md5HashUtil = new MD5HashUtil();
String result =
userRepo.changePassword("UPD",0,0,user.getEmail(),md5HashUtil.md5(user.getPassword()),Sessio
nManager.getInstance().getIp());
return result; // Will return 'Success!' or appropriate error message
}
@Transactional
public List<LoginHistoryReq> bindLoginHistory(String mode, int userId) {
List<?> result = userRepo.bindLoginHistory(mode,userId);
List<LoginHistoryReq> loginHistoryList = new ArrayList<>();

for (Object o : result) {


if (o instanceof Object[]) {
Object[] row = (Object[]) o;
if (row.length >= 7) {
String firstName = (String) row[0];
String loginId = (String) row[1];
String password = (String) row[2];
String userTypeName = (String) row[3];

75
Date loginDate = (Date) row[4];
Date logoutDate = (Date) row[5];
double totalDuration = (double) row[6];

LoginHistoryReq loginHistoryReq = new LoginHistoryReq(firstName,loginId, password,


userTypeName, loginDate, logoutDate, totalDuration);
loginHistoryList.add(loginHistoryReq);
}
else {
throw new IllegalArgumentException("Error Found: " + Arrays.toString(row));
}
} else {
throw new ClassCastException("Error Found: " + o.getClass());
}
}
return loginHistoryList;
}
}

Interface: GenderMasterRepo

package io.flappybird.repo;

import io.flappybird.model.GenderMasterReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GenderMasterRepo extends JpaRepository<GenderMasterReq,Integer> {
@Procedure("StudentInfo")
List<GenderMasterReq> bindDdlGender(String mode);
}

Interface: GradeMasterRepo

package io.flappybird.repo;

import io.flappybird.model.GradeMasterReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GradeMasterRepo extends JpaRepository<GradeMasterReq,Integer> {
@Procedure("StudentInfo")
List<GradeMasterReq> bindDdlGrade(String mode);
}

76
Interface: PlayGameRepo

package io.flappybird.repo;

import io.flappybird.model.UserDetailsEntityReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface PlayGameRepo extends JpaRepository<UserDetailsEntityReq, Long> {
@Procedure(procedureName = "PlayGame")
String startGame(
@Param("Mode") String mode,
@Param("IQuizId") int quizId,
@Param("ICorrectAns") int correctAns,
@Param("IUserId") int userId,
@Param("IIPAddress") String ipAddress);
@Procedure(procedureName = "PlayGame")
String endGame(
@Param("Mode") String mode,
@Param("IQuizId") int quizId,
@Param("ICorrectAns") int correctAns,
@Param("IUserId") int userId,
@Param("IIPAddress") String ipAddress);
}

Interface: QuestionRepo

package io.flappybird.repo;
import io.flappybird.model.GenderMasterReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface QuestionRepo extends JpaRepository<GenderMasterReq,Long> {

@Procedure(procedureName = "QuestionInfo")
List getQuizInfo(
@Param("IMode") String mode,
@Param("IQuizId") Integer quizId,
@Param("IQuestionId") Integer questionId,
@Param("IQuestionDescription") String questionDescription,
@Param("IQuestionHint") String questionHint,
@Param("IOptionA") String optionA,
@Param("IOptionB") String optionB,

77
@Param("IOptionC") String optionC,
@Param("IOptionD") String optionD,
@Param("IOptionE") String optionE,
@Param("IAnswer") String answer,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String iPAddress,
@Param("IUserId") Integer userId
);
@Procedure(procedureName = "QuestionInfo")
List bindQuestionInfo(
@Param("IMode") String mode,
@Param("IQuizId") Integer quizId,
@Param("IQuestionId") Integer questionId,
@Param("IQuestionDescription") String questionDescription,
@Param("IQuestionHint") String questionHint,
@Param("IOptionA") String optionA,
@Param("IOptionB") String optionB,
@Param("IOptionC") String optionC,
@Param("IOptionD") String optionD,
@Param("IOptionE") String optionE,
@Param("IAnswer") String answer,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String iPAddress,
@Param("IUserId") Integer userId
);

@Procedure(procedureName = "QuestionInfo")
List bindQuestionsInfo(
@Param("IMode") String mode,
@Param("IQuizId") Integer quizId,
@Param("IQuestionId") Integer questionId,
@Param("IQuestionDescription") String questionDescription,
@Param("IQuestionHint") String questionHint,
@Param("IOptionA") String optionA,
@Param("IOptionB") String optionB,
@Param("IOptionC") String optionC,
@Param("IOptionD") String optionD,
@Param("IOptionE") String optionE,
@Param("IAnswer") String answer,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String iPAddress,
@Param("IUserId") Integer userId
);

@Procedure(procedureName = "QuestionInfo")
List bindQuizList(String mode);

Interface: QuizRepo

78
package io.flappybird.repo;
import io.flappybird.model.UserDetailsEntityReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface QuizRepo<E> extends JpaRepository<UserDetailsEntityReq, Long> {

@Procedure("QuizInfo")
List bindTopicList(String mode);
@Procedure("QuizInfo")
List bindQuizInfo(String mode);
@Procedure(procedureName = "QuizInfo")
List getQuizListByTopics(
@Param("Mode") String mode,
@Param("IQuizId") Integer quizId,
@Param("IQuizName") String quizName,
@Param("ITeacherId") Integer teacherId,
@Param("ITopicId") Integer topicId,
@Param("ILevelId") Integer levelId,
@Param("ITotalQuestions") Integer totalQuestions,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String iPAddress,
@Param("IUserId") Integer userId
);

Interface: StudentRepo

package io.flappybird.repo;

import io.flappybird.model.StudentReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface StudentRepo extends JpaRepository<StudentReq,Integer> {
@Procedure("StudentInfo")
List<StudentReq> bindStudentInfo(String mode);

@Procedure("StudentInfo")
List bindStudentList(String mode);

@Procedure(procedureName = "StudentInfo")
List getStudentByUserId(

79
@Param("Mode") String mode,
@Param("IStudentId") Integer studentId,
@Param("ISurname") String surName,
@Param("IfirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IGradeId") Integer gradeId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("ITotalTrophies") Integer totalTrophies,
@Param("ItotalCertificates") Integer totalCertificates,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);
@Procedure(procedureName = "StudentInfo")
String updateStudentProfile(
@Param("Mode") String mode,
@Param("IStudentId") Integer studentId,
@Param("ISurname") String surName,
@Param("IfirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IGradeId") Integer gradeId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("ITotalTrophies") Integer totalTrophies,
@Param("ItotalCertificates") Integer totalCertificates,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);
@Procedure(procedureName = "StudentInfo")
List bindAchievements(
@Param("Mode") String mode,
@Param("IStudentId") Integer studentId,
@Param("ISurname") String surName,
@Param("IfirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IGradeId") Integer gradeId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("ITotalTrophies") Integer totalTrophies,
@Param("ItotalCertificates") Integer totalCertificates,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);

80
@Procedure(procedureName = "StudentInfo")
StudentReq getStudentId(
@Param("Mode") String mode,
@Param("IStudentId") Integer studentId,
@Param("ISurname") String surName,
@Param("IfirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IGradeId") Integer gradeId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("ITotalTrophies") Integer totalTrophies,
@Param("ItotalCertificates") Integer totalCertificates,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);

@Procedure(procedureName = "StudentInfo")
String deleteStudentInfo(
@Param("Mode") String mode,
@Param("IStudentId") Integer studentId,
@Param("ISurname") String surName,
@Param("IfirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IGradeId") Integer gradeId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("ITotalTrophies") Integer totalTrophies,
@Param("ItotalCertificates") Integer totalCertificates,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);

Interface: TeacherRepo

package io.flappybird.repo;
import io.flappybird.model.TeacherReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

81
import java.util.List;

@Repository
public interface TeacherRepo extends JpaRepository<TeacherReq, Integer>{
@Procedure(procedureName = "TeacherInfo")
List getTeacherByUserId(
@Param("Mode") String mode,
@Param("ITeacherId") Integer teacherId,
@Param("ISurname") String surName,
@Param("IFirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);
@Procedure(procedureName = "TeacherInfo")
String updateTeacherProfile(
@Param("Mode") String mode,
@Param("ITeacherId") Integer teacherId,
@Param("ISurname") String surName,
@Param("IFirstName") String firstName,
@Param("IPwd") String pwd,
@Param("IAge") Integer age,
@Param("IGenderId") Integer genderId,
@Param("IEmailId") String emailId,
@Param("IMobileNo") String mobileNo,
@Param("IisActive") Boolean isActive,
@Param("IIPAddress") String ipAddress,
@Param("IUserId") Integer userId
);

}
Interface: TopicRepo

package io.flappybird.repo;
import io.flappybird.model.UserDetailsEntityReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface TopicRepo <E> extends JpaRepository<UserDetailsEntityReq, Long> {
@Procedure("TopicInfo")
List bindStudentList(String mode);
@Procedure(procedureName = "TopicInfo")

82
List topicsStatus(
@Param("Mode") String mode,
@Param("ITopicId") Integer topicId,
@Param("ITopicName") String topicName,
@Param("IisActive") Boolean isActive,
@Param("IUserId") Integer userId
);
@Procedure("QuizInfo")
List getTopicsList(String mode);

Interface: UserRepo

package io.flappybird.repo;
import io.flappybird.model.UserDetailsEntityReq;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface UserRepo extends JpaRepository<UserDetailsEntityReq, Long> {
@Procedure(procedureName = "SignUpInfo")
String signUpUser(
@Param("IMode") String mode,
@Param("IUserTypeId") int userTypeId,
@Param("ISurname") String surName,
@Param("IFirstName") String firstName,
@Param("IGenderId") int genderId,
@Param("IMobileNo") String mobileNo,
@Param("IEmailId") String emailId,
@Param("IPwd") String pwd,
@Param("IIPAddress") String ipAddress);

@Procedure(procedureName = "LoginInfo")
String loginUser(
@Param("IMode") String mode,
@Param("IUserId") int userId,
@Param("IUserTypeId") int userTypeId,
@Param("ILoginId") String loginId,
@Param("IPwd") String password,
@Param("IIPAddress") String ipAddress);
@Procedure(procedureName = "LoginInfo")
int getLoginUserId(
@Param("IMode") String mode,
@Param("IUserId") int userId,
@Param("IUserTypeId") int userTypeId,
@Param("ILoginId") String loginId,
@Param("IPwd") String password,
@Param("IIPAddress") String ipAddress);

83
@Procedure(procedureName = "LoginInfo")
String getLoginUserName(
@Param("IMode") String mode,
@Param("IUserId") int userId,
@Param("IUserTypeId") int userTypeId,
@Param("ILoginId") String loginId,
@Param("IPwd") String password,
@Param("IIPAddress") String ipAddress);
@Procedure(procedureName = "LoginInfo")
String logOutUser(
@Param("IMode") String mode,
@Param("IUserId") int userId,
@Param("IUserTypeId") int userTypeId,
@Param("ILoginId") String loginId,
@Param("IPwd") String password,
@Param("IIPAddress") String ipAddress);
@Procedure(procedureName = "LoginInfo")
String changePassword(
@Param("IMode") String mode,
@Param("IUserId") int userId,
@Param("IUserTypeId") int userTypeId,
@Param("ILoginId") String loginId,
@Param("IPwd") String password,
@Param("IIPAddress") String ipAddress);

@Procedure("LoginInfo")
List bindLoginHistory(String mode, int userId);

HTML Template: StartGame

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Start Game Page</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" th:href="@{/css/login.css}" />
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 500px;

84
margin: 40px auto;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}

.form-group {
margin-bottom: 15px;
}

.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}

.form-group button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}

.form-group button:hover {
background-color: #45a049;
}

85
/* Responsive Styles */
@media (max-width: 768px) {
.form-group button {
font-size: 14px;
}
}

@media (max-width: 480px) {


.container {
padding: 15px;
margin-top: 20px;
}

h2 {
font-size: 24px;
}

.form-group select {
padding: 8px;
}
}

#playButton:disabled {
background-color: #ccc; /* Gray color for disabled state */
color: #666; /* Faded text color */
cursor: not-allowed; /* Change cursor to indicate it's not clickable */
}

#playButton {
background-color: #007bff; /* Primary color */
color: white; /* Text color */
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 5px; /* Rounded corners */
transition: background-color 0.3s; /* Smooth transition */
}

#playButton:hover:not(:disabled) {
background-color: #0056b3; /* Darker shade on hover */
}
#readMeButton {
background-color: #007bff; /* Primary color */
color: white; /* Text color */
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 5px; /* Rounded corners */
transition: background-color 0.3s; /* Smooth transition */
}

86
</style>

<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() {
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OKK'
});
}
});
</script>

<script>
$(document).ready(function() {
$('#topicName').change(function() {
var topicId = $(this).val();
if (topicId) {
$.ajax({
url: '/game/quizzes/' + topicId,
method: 'GET',
success: function(data) {
var quizList = $('#quizList');
quizList.empty(); // Clear existing options
quizList.append('<option value="" disabled selected>Select Quiz</option>'); // Add
default option

$.each(data, function(index, quiz) {


quizList.append('<option value="' + quiz.quizId + '">' + quiz.quizName +
'</option>');
});
},
error: function() {
alert("Failed to fetch quizzes. Please try again.");
}
});
} else {
$('#quizList').empty(); // Clear if no topic is selected
$('#quizList').append('<option value="" disabled selected>Select Quiz</option>'); // Add
default option
}
checkSelection(); // Recheck the selections after topic change
});

$('#quizList').change(function() {
checkSelection(); // Recheck the selections after quiz change
});
});

87
function checkSelection() {
const topicSelect = document.getElementById('topicName');
const quizSelect = document.getElementById('quizList');
const playButton = document.getElementById('playButton');

// Enable the button if both selections are made


if (topicSelect.value && quizSelect.value) {
playButton.disabled = false;
} else {
playButton.disabled = true;
}
}

function playGame() {
const quizSelect = document.getElementById('quizList');
const selectedQuizId = quizSelect.value;

// Redirect to the game page with the selected quiz ID


window.location.href = '/game/game/' + selectedQuizId;
}

function deleteHighestScore() {
window.location.href = '/game/deleteHighestScore';
}

function readMe() {
const instructionsDiv = $('#instructions');

// Check if the instructions are currently visible


if (instructionsDiv.is(':visible')) {
// Hide the instructions if they are currently displayed
instructionsDiv.hide();
} else {
// Show loading message
instructionsDiv.html('<p>Loading...</p>').show();

// Fetch the instructions


$.ajax({
url: '/game/readMe',
type: 'GET',
success: function(data) {
if (data) {
instructionsDiv.html(data); // Display the returned content
} else {
instructionsDiv.html('<p>No instructions available.</p>');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("Error fetching game instructions: " + textStatus, errorThrown);
instructionsDiv.html('<p>Failed to load instructions. Please try again.</p>');
}
});

88
}
}
</script>
</head>
<body>
<div class="container">
<form class="game-form" th:object="${scoreReq}">
<h2>Play Game</h2>
<div class="form-group">
<label for="highestScore">Highest Score</label>
<input type="text" id="highestScore" name="highestScore" th:field="*{highestScore}" disabled>
</div>

<div class="form-group">
<label for="recentScore">Recent Score</label>
<input type="text" id="recentScore" name="recentScore" th:field="*{recentScore}" disabled>
</div>

<div class="form-group">
<label for="topicName">Topic Name</label>
<select id="topicName" name="topicName">
<option value="" disabled selected>Select Topic</option>
<option th:each="topic : ${topics}"
th:value="${topic.topicId}"
th:text="${topic.topicName}"></option>
</select>
</div>

<div class="form-group">
<label for="quizList">Quiz</label>
<select id="quizList" name="quiz">
<option value="" disabled selected>Select Quiz</option>
<!-- Options will be dynamically inserted here -->
</select>
</div>

<div class="form-group">
<button id="playButton" type="button" onclick="playGame()" disabled>Play Game</button>
</div>

<div class="form-group">
<button type="button" onclick="window.location.href='/student/studentMenu'">Back to
Home</button>
</div>

<div class="form-group">
<button id="readMeButton" type="button" onclick="readMe();">Game Instructions</button>
</div>
<div id="instructions" style="display:none;"></div>
</form>
</div>
</body>

89
</html>

HTML Template: Achievements

th:text="${topic.topicName}"></option>
</select>
</div>
<div class="form-group">
<label for="quizList">Quiz</label>
<select id="quizList" name="quiz">
<option value="" disabled selected>Select Quiz</option>
<!-- Options will be dynamically inserted here -->
</select>
</div>
<div class="form-group">
<button id="playButton" type="button" onclick="playGame()"​
disabled>Play Game</button>
</div>
<div class="form-group">
<button type="button"​
onclick="window.location.href='/student/studentMenu'">Back to Home</button>
</div>
<div class="form-group">
<button id="readMeButton" type="button" onclick="readMe();">Game​
Instructions</button>
</div>
<div id="instructions" style="display:none;"></div>
</form>
</div>
</body>
</html>

HTML Template: Student

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Students Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

90
<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
display: flex;
flex-wrap: wrap;
margin-bottom: 15px;
}

.form-group label {
flex: 0 0 25%;
padding: 10px;
}

.form-group input,
.form-group select {
flex: 1;
padding: 10px;
margin-right: 10px;
}

.form-group input[type="submit"] {
background-color: #4CAF50;

91
color: white;
border: none;
cursor: pointer;
flex: 0 0 100%;
}

.form-group input[type="submit"]:hover {
background-color: #45a049;
}

.form-group button {
padding: 10px;
background-color: #f44336;
color: white;
border: none;
cursor: pointer;
}

.form-group button:hover {
background-color: #d32f2f;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Icon button styling */


.icon-btn {

92
background-color: #f0f0f0; /* Light gray background */
border: 1px solid #ccc; /* Light border */
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333; /* Icon color */
transition: background-color 0.3s ease;
}

.icon-btn.edit {
color: #4CAF50; /* Green for edit */
}

.icon-btn.delete {
color: #f44336; /* Red for delete */
}

.icon-btn:hover {
background-color: #ddd; /* Slight background color change on hover */
}

/* Specific styling for IP Address and User ID */


.hidden-column {
font-size: 10px;
visibility: hidden;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
</style>

<script th:inline="javascript">

93
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
</script>
</head>
<body>
<div class="container">
<h1>Students Details</h1>
<table border="1">
<thead>
<tr>
<th>S.No</th>
<th>Surname</th>
<th>FirstName</th>
<th>Age</th>
<th>Gender</th>
<th>Grade</th>
<th>Email ID</th>
<th>Mobile No</th>
<th>Trophies</th>
<th>Certificates</th>
<!-- <th class="hidden-column">IP Address</th> &lt;!&ndash; Make invisible
&ndash;&gt;-->
<th> Reg.Date </th>
<th>isActive</th>
<th>Action</th>
<!-- <th class="hidden-column">User ID</th> &lt;!&ndash; Make invisible
&ndash;&gt;-->
</tr>
</thead>
<tbody>
<tr th:each="student, stat : ${students}">
<td th:text="${stat.index + 1}"></td>
<td th:text="${student.surName}"></td>
<td th:text="${student.firstName}"></td>
<td th:text="${student.age}"></td>
<td th:text="${student.gender}"></td>
<td th:text="${student.grade}"></td>

94
<td th:text="${student.emailId}"></td>
<td th:text="${student.mobileNo}"></td>
<td th:text="${student.totalTrophies}"></td>
<td th:text="${student.totalCertificates}"></td>
<!-- <td th:text="${student.ipAddress}" class="hidden-column"></td> &lt;!&ndash;
Invisible &ndash;&gt;-->
<td th:text="${student.transDate}"></td>
<td th:text="${student.isActive} ? 'Yes' : 'No'"></td>
<!-- <td th:text="${student.userId}" class="hidden-column"></td> &lt;!&ndash; Invisible
&ndash;&gt;-->
<td>
<a th:href="@{/students/edit/{id}(id=${student.studentId})}">
<button class="icon-btn edit">
<i class="fas fa-edit"></i>
</button>
</a>
<a th:href="@{/students/delete/{id}(id=${student.studentId})}" onclick="return confirm('Are
you sure?');">
<button class="icon-btn delete">
<i class="fas fa-trash"></i>
</button>
</a>
</td>
</tr>

</tbody>
</table>
</div>
</body>
</html>

HTML Template: StudentMenu

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Home Page</title>
<link rel="stylesheet" th:href="@{/css/home.css}" />
<style>
body {
font-family: Arial, sans-serif;

95
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

.home-container {
width: 100%;
max-width: 600px;
margin: 40px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}

.home-form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 15px; /* Adding gap for consistent spacing */
}

.form-group {
flex: 1 1 48%;
margin-bottom: 15px;
}

.form-group.full-width {
flex: 1 1 100%;
}

.form-group button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;

96
border-radius: 5px;
font-size: 16px;
}

.form-group button:hover {
background-color: #45a049;
}
.user-name {
text-align: center;
font-size: 20px;
font-weight: bold;
color: #555;
margin-bottom: 20px;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.form-group {
flex: 1 1 100%;
margin-bottom: 10px;
}

.form-group button {
font-size: 14px;
padding: 10px;
}
}

@media (max-width: 480px) {


.home-container {
padding: 15px;
}

h2 {
font-size: 24px;
}

.form-group button {
font-size: 14px;
padding: 8px;
}
}

@media (max-width: 360px) {


.form-group button {

97
font-size: 12px;
padding: 6px;
}
}
</style>
</head>
<body>
<div class="home-container">
<form class="home-form">
<div class="user-name" th:text="'Welcome, ' + ${userName} + ' '" ></div>
<div class="form-group full-width">
<h2>Main Menu</h2>
</div>
<div class="form-group full-width">
<button type="button" onclick="window.location.href='/game/playGame'">Start Game</button>
</div>

<!-- 2-column layout buttons -->


<div class="form-group">
<button type="button" onclick="window.location.href='/student/topicsStatus'">Topic wise
Status</button>
</div>
<div class="form-group">
<button type="button"
onclick="window.location.href='/student/achievements'">Achievements</button>
</div>

<div class="form-group">
<button type="button" onclick="window.location.href='/student/studentPerformance'">Student
Performance</button>
</div>
<div class="form-group">
<button type="button" onclick="window.location.href='/user/loginHistory'">Login
History</button>
</div>

<!-- Password & Logout -->


<div class="form-group">
<button type="button" onclick="window.location.href='/user/changePassword'">Change
Password</button>
</div>
<div class="form-group">
<button type="button" onclick="window.location.href='/student/updateStudentProfile'">Update
Profile</button>

98
</div>
<div class="form-group full-width">
<button type="button" onclick="window.location.href='/user/logOut'">Logout</button>
</div>

</form>
</div>
</body>
</html>

HTML Template: StudentPerformance

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Student Performance Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;

99
margin-bottom: 20px;
}

.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}

.form-group-back button:hover {
background-color: #45a049;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Pagination styles */
.pagination {
margin-top: 20px;
text-align: center;
display: flex;
justify-content: center;

100
align-items: center;
}

.pagination a, .pagination span {


color: white;
padding: 10px 20px;
text-decoration: none;
margin: 0 5px;
border: 1px solid #4CAF50;
background-color: #4CAF50;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

.pagination a.disabled {
background-color: #ddd;
color: #888;
cursor: not-allowed;
}

.pagination span {
background-color: #4CAF50;
cursor: default;
}

.pagination a:hover:not(.disabled) {
background-color: #45a049;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
</style>
</head>
<body>

101
<div class="container">
<h1>Student Performance Details</h1>
<div class="form-group-back">
<button type="button" onclick="window.location.href='/student/studentMenu'">Back to
Home</button>
</div>

<table class="table table-bordered" id="performanceTable">


<thead>
<tr>
<th>S.No</th>
<th>Topic-Quiz Name</th>
<th>Created By</th>
<th>Questions</th>
<th>Max M.</th>
<th>Min M.</th>
<th>Minutes</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>Accuracy</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr th:each="topic,stat : ${topicStatusReq}">
<td th:text="${stat.index + 1}"></td>
<td th:text="${topic.quizName}"></td>
<td th:text="${topic.teacherName}"></td>
<td th:text="${topic.totalQuestions}"></td>
<td th:text="${topic.maxMarks}"></td>
<td th:text="${topic.minMarks}"></td>
<td th:text="${topic.duration}"></td>
<td th:text="${#dates.format(topic.playDate, 'dd-MM-yyyy')}"></td>
<td th:text="${#dates.format(topic.startTime, 'HH:mm:ss')}"></td>
<td th:text="${#dates.format(topic.endTime, 'HH:mm:ss')}"></td>
<td th:text="${topic.accuracy}"></td>
<td th:text="${topic.result}"></td>
</tr>
</tbody>
</table>

<!-- Pagination controls -->


<div class="pagination" id="pagination">

102
<!-- Pagination buttons will be dynamically generated here -->
</div>
</div>

<script>
const rowsPerPage = 10;
const table = document.getElementById('performanceTable');
const pagination = document.getElementById('pagination');
const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
const totalRows = rows.length;
const totalPages = Math.ceil(totalRows / rowsPerPage);

let currentPage = 1;

function displayPage(page) {
currentPage = page;
const startRow = (page - 1) * rowsPerPage;
const endRow = startRow + rowsPerPage;

for (let i = 0; i < totalRows; i++) {


rows[i].style.display = (i >= startRow && i < endRow) ? '' : 'none';
}

updatePagination();
}

function updatePagination() {
pagination.innerHTML = '';

// Previous button
const prevBtn = document.createElement('a');
prevBtn.innerHTML = 'Previous';
if (currentPage > 1) {
prevBtn.onclick = () => displayPage(currentPage - 1);
} else {
prevBtn.classList.add('disabled');
}
pagination.appendChild(prevBtn);

// Page number display


const pageInfo = document.createElement('span');
pageInfo.innerHTML = `Page ${currentPage} of ${totalPages}`;
pagination.appendChild(pageInfo);

103
// Next button
const nextBtn = document.createElement('a');
nextBtn.innerHTML = 'Next';
if (currentPage < totalPages) {
nextBtn.onclick = () => displayPage(currentPage + 1);
} else {
nextBtn.classList.add('disabled');
}
pagination.appendChild(nextBtn);
}

// Initially display the first page


displayPage(1);
</script>

</body>
</html>

HTML Template: PlayGame

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Topic Wise Status Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

104
h2 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
display: flex;
flex-wrap: wrap;
margin-bottom: 15px;
}

.form-group label {
flex: 0 0 25%;
padding: 10px;
}

.form-group input,
.form-group select {
flex: 1;
padding: 10px;
margin-right: 10px;
}

.form-group input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
flex: 0 0 100%;
}

.form-group input[type="submit"]:hover {
background-color: #45a049;
}

.form-group button {
padding: 10px;
background-color: #f44336;
color: white;
border: none;
cursor: pointer;
}

.form-group button:hover {
background-color: #d32f2f;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;

105
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Icon button styling */


.icon-btn {
background-color: #f0f0f0; /* Light gray background */
border: 1px solid #ccc; /* Light border */
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333; /* Icon color */
transition: background-color 0.3s ease;
}

.icon-btn.edit {
color: #4CAF50; /* Green for edit */
}

.icon-btn.delete {
color: #f44336; /* Red for delete */
}

.icon-btn:hover {
background-color: #ddd; /* Slight background color change on hover */
}

/* Specific styling for IP Address and User ID */


.hidden-column {
font-size: 10px;
visibility: hidden;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;

106
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
.form-group-back button:hover {
background-color: #45a049;
}
/* Pagination styles */
.pagination {
margin-top: 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}

.pagination a, .pagination span {


color: white;
padding: 10px 20px;
text-decoration: none;
margin: 0 5px;
border: 1px solid #4CAF50;
background-color: #4CAF50;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

.pagination a.disabled {
background-color: #ddd;
color: #888;
cursor: not-allowed;
}

.pagination span {
background-color: #4CAF50;
cursor: default;
}

107
.pagination a:hover:not(.disabled) {
background-color: #45a049;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
</style>

<script th:inline="javascript">
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
</script>
</head>
<body>
<div class="container">
<h1>Topic Wise Status Details</h1>
<div class="form-group-back">
<button type="button" onclick="window.location.href='/student/studentMenu'">Back to
Home</button>
</div>
<table class="table table-bordered" id="topicStatusTable">
<thead>
<tr>
<th>S.No</th>
<!-- <th>Topic Name</th>-->
<th>Topic-Quiz Name</th>
<th>Created By</th>
<th>Questions</th>
<th>Max M.</th>
<th>Min M.</th>
<th>Minutes</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>Accuracy</th>
<th>Result</th>

108
</tr>
</thead>
<tbody>
<tr th:each="topic,stat : ${topicStatusReq}">
<td th:text="${stat.index + 1}"></td>
<!-- <td th:text="${topic.topicName}"></td>-->
<td th:text="${topic.quizName}"></td>
<td th:text="${topic.teacherName}"></td>
<td th:text="${topic.totalQuestions}"></td>
<td th:text="${topic.maxMarks}"></td>
<td th:text="${topic.minMarks}"></td>
<td th:text="${topic.duration}"></td>
<td th:text="${#dates.format(topic.playDate, 'dd-MM-yyyy')}"></td>
<td th:text="${#dates.format(topic.startTime, 'HH:mm:ss')}"></td>
<td th:text="${#dates.format(topic.endTime, 'HH:mm:ss')}"></td>
<td th:text="${topic.accuracy}"></td>
<td th:text="${topic.result}"></td>
</tr>
</tbody>
</table>

<!-- Pagination controls -->


<div class="pagination" id="pagination">
<!-- Pagination buttons will be dynamically generated here -->
</div>
</div>

<script>
const rowsPerPage = 10;
const table = document.getElementById('topicStatusTable');
const pagination = document.getElementById('pagination');
const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
const totalRows = rows.length;
const totalPages = Math.ceil(totalRows / rowsPerPage);

let currentPage = 1;

function displayPage(page) {
currentPage = page;
const startRow = (page - 1) * rowsPerPage;
const endRow = startRow + rowsPerPage;

for (let i = 0; i < totalRows; i++) {


rows[i].style.display = (i >= startRow && i < endRow) ? '' : 'none';
}

updatePagination();
}

function updatePagination() {
pagination.innerHTML = '';

109
// Previous button
const prevBtn = document.createElement('a');
prevBtn.innerHTML = 'Previous';
if (currentPage > 1) {
prevBtn.onclick = () => displayPage(currentPage - 1);
} else {
prevBtn.classList.add('disabled');
}
pagination.appendChild(prevBtn);

// Page number display


const pageInfo = document.createElement('span');
pageInfo.innerHTML = `Page ${currentPage} of ${totalPages}`;
pagination.appendChild(pageInfo);

// Next button
const nextBtn = document.createElement('a');
nextBtn.innerHTML = 'Next';
if (currentPage < totalPages) {
nextBtn.onclick = () => displayPage(currentPage + 1);
} else {
nextBtn.classList.add('disabled');
}
pagination.appendChild(nextBtn);
}

// Initially display the first page


displayPage(1);
</script>
</body>
</html>

HTML Template: TopicStatus

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Topic Wise Status Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;

110
}

.container {
width: 100%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
display: flex;
flex-wrap: wrap;
margin-bottom: 15px;
}

.form-group label {
flex: 0 0 25%;
padding: 10px;
}

.form-group input,
.form-group select {
flex: 1;
padding: 10px;
margin-right: 10px;
}

.form-group input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
flex: 0 0 100%;
}

.form-group input[type="submit"]:hover {
background-color: #45a049;
}

.form-group button {
padding: 10px;
background-color: #f44336;
color: white;
border: none;
cursor: pointer;

111
}

.form-group button:hover {
background-color: #d32f2f;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Icon button styling */


.icon-btn {
background-color: #f0f0f0; /* Light gray background */
border: 1px solid #ccc; /* Light border */
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333; /* Icon color */
transition: background-color 0.3s ease;
}

.icon-btn.edit {
color: #4CAF50; /* Green for edit */
}

.icon-btn.delete {
color: #f44336; /* Red for delete */
}

.icon-btn:hover {
background-color: #ddd; /* Slight background color change on hover */
}

112
/* Specific styling for IP Address and User ID */
.hidden-column {
font-size: 10px;
visibility: hidden;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
.form-group-back button:hover {
background-color: #45a049;
}
/* Pagination styles */
.pagination {
margin-top: 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}

.pagination a, .pagination span {


color: white;
padding: 10px 20px;
text-decoration: none;
margin: 0 5px;
border: 1px solid #4CAF50;
background-color: #4CAF50;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

.pagination a.disabled {

113
background-color: #ddd;
color: #888;
cursor: not-allowed;
}

.pagination span {
background-color: #4CAF50;
cursor: default;
}

.pagination a:hover:not(.disabled) {
background-color: #45a049;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
</style>

<script th:inline="javascript">
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
</script>
</head>
<body>
<div class="container">
<h1>Topic Wise Status Details</h1>
<div class="form-group-back">
<button type="button" onclick="window.location.href='/student/studentMenu'">Back to
Home</button>
</div>
<table class="table table-bordered" id="topicStatusTable">
<thead>
<tr>
<th>S.No</th>
<!-- <th>Topic Name</th>-->
<th>Topic-Quiz Name</th>

114
<th>Created By</th>
<th>Questions</th>
<th>Max M.</th>
<th>Min M.</th>
<th>Minutes</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>Accuracy</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr th:each="topic,stat : ${topicStatusReq}">
<td th:text="${stat.index + 1}"></td>
<!-- <td th:text="${topic.topicName}"></td>-->
<td th:text="${topic.quizName}"></td>
<td th:text="${topic.teacherName}"></td>
<td th:text="${topic.totalQuestions}"></td>
<td th:text="${topic.maxMarks}"></td>
<td th:text="${topic.minMarks}"></td>
<td th:text="${topic.duration}"></td>
<td th:text="${#dates.format(topic.playDate, 'dd-MM-yyyy')}"></td>
<td th:text="${#dates.format(topic.startTime, 'HH:mm:ss')}"></td>
<td th:text="${#dates.format(topic.endTime, 'HH:mm:ss')}"></td>
<td th:text="${topic.accuracy}"></td>
<td th:text="${topic.result}"></td>
</tr>
</tbody>
</table>

<!-- Pagination controls -->


<div class="pagination" id="pagination">
<!-- Pagination buttons will be dynamically generated here -->
</div>
</div>

<script>
const rowsPerPage = 10;
const table = document.getElementById('topicStatusTable');
const pagination = document.getElementById('pagination');
const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
const totalRows = rows.length;
const totalPages = Math.ceil(totalRows / rowsPerPage);

let currentPage = 1;

function displayPage(page) {
currentPage = page;
const startRow = (page - 1) * rowsPerPage;
const endRow = startRow + rowsPerPage;

115
for (let i = 0; i < totalRows; i++) {
rows[i].style.display = (i >= startRow && i < endRow) ? '' : 'none';
}

updatePagination();
}

function updatePagination() {
pagination.innerHTML = '';

// Previous button
const prevBtn = document.createElement('a');
prevBtn.innerHTML = 'Previous';
if (currentPage > 1) {
prevBtn.onclick = () => displayPage(currentPage - 1);
} else {
prevBtn.classList.add('disabled');
}
pagination.appendChild(prevBtn);

// Page number display


const pageInfo = document.createElement('span');
pageInfo.innerHTML = `Page ${currentPage} of ${totalPages}`;
pagination.appendChild(pageInfo);

// Next button
const nextBtn = document.createElement('a');
nextBtn.innerHTML = 'Next';
if (currentPage < totalPages) {
nextBtn.onclick = () => displayPage(currentPage + 1);
} else {
nextBtn.classList.add('disabled');
}
pagination.appendChild(nextBtn);
}

// Initially display the first page


displayPage(1);
</script>
</body>
</html>

HTML Template: Question

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Quiz Question Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"

116
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
/* General Styles */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
margin-bottom: 20px;
}

/* Form Group */
.form-group {
margin-bottom: 15px;
}

.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

/* Back Button */
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
transition: background-color 0.3s;
}

.form-group-back button:hover {
background-color: #45a049;

117
}

/* Table Styling */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}

th {
background-color: #4CAF50;
color: white;
}

/* Responsive Design */
@media screen and (max-width: 768px) {
th, td {
font-size: 14px;
padding: 8px;
}

.form-group-back button {
font-size: 14px;
padding: 10px;
}
}
</style>

<script th:inline="javascript">
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
</script>

<script>
$(document).ready(function() {
$('#quizSelect').change(function() {
var quizId = $(this).val();
if (quizId) {
$.ajax({

118
url: '/teacher/questions/' + quizId,
method: 'GET',
success: function(data) {
var questionsBody = $('#questionsBody');
questionsBody.empty(); // Clear existing rows
$('#questionsTable').show(); // Show the table

$.each(data, function(index, que) {


questionsBody.append('<tr>' +
'<td>' + (index + 1) + '</td>' +
'<td>' + que.questionDescription + '</td>' +
'<td>' + que.questionHint + '</td>' +
'<td>' + que.optionA + '</td>' +
'<td>' + que.optionB + '</td>' +
'<td>' + que.optionC + '</td>' +
'<td>' + que.optionD + '</td>' +
'<td>' + que.optionE + '</td>' +
'<td>' + que.answer + '</td>' +
'</tr>');
});
},
error: function() {
alert("Failed to fetch questions. Please try again.");
}
});
} else {
$('#questionsBody').empty(); // Clear if no student is selected
$('#questionsTable').hide(); // Hide the table
}
});
});
</script>
</head>
<body>
<div class="container">
<h1>Quiz Question Details</h1>
<div class="form-group-back">
<button type="button" onclick="window.location.href='/teacher/teacherMenu'">Back to
Home</button>
</div>
<div class="form-group">
<label></label>
</div>
<div class="form-group">
<label for="quizSelect">Quiz:</label>
<select id="quizSelect" name="quizId">

<option value="" disabled selected>Select Quiz</option>


<option th:each="quiz : ${quizDDLReq}"
th:value="${quiz.quizId}"
th:text="${quiz.quizName}"></option>
</select>

119
</div>
<table id="questionsTable" style="display:none;">
<thead>
<tr>
<th>S.No</th>
<th>Question</th>
<th>Question Hint</th>
<th>Option A</th>
<th>Option B</th>
<th>Option C</th>
<th>Option D</th>
<th>Option E</th>
<th>Answer</th>
</tr>
</thead>
<tbody id="questionsBody">
<!-- Rows will be dynamically inserted here -->
</tbody>
</table>
</div>
</body>
</html>

HTML Template: UpdateStudentProfile

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Profile Details Page</title>
<link rel="stylesheet" th:href="@{/css/login.css}" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

.student-container {
width: 100%;
max-width: 600px;
margin: auto;
background-color: white;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}

120
.student-form {
display: flex;
flex-wrap: wrap;
}

.form-group {
flex: 0 0 48%;
margin: 10px 1%;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}

.form-group label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}

.student-form button {
width: 100%;
padding: 15px;
margin-top: 20px;
background-color: #4CAF50;
border: none;
color: white;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}

.student-form button:hover {
background-color: #45a049;
}

.full-width {
flex: 0 0 100%;
}

h2 {
text-align: center;
width: 100%;
margin-bottom: 20px;
}

121
.radio-group {
display: flex;
gap: 10px;
padding: 10px 0;
}

.radio-group input {
margin-right: 5px;
}

/* Modal styles */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}

.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 300px;
text-align: center;
}

.modal-content button {
padding: 10px 20px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;
}

.modal-content button:hover {
background-color: #45a049;
}

.error-message {
color: red;
}

/* Responsive Styles */

122
@media (max-width: 768px) {
.form-group {
flex: 0 0 100%;
margin: 10px 0;
}

.student-form button {
padding: 12px;
font-size: 14px;
}

.radio-group {
flex-direction: column;
align-items: flex-start;
}
}

@media (max-width: 480px) {


.student-container {
padding: 15px;
}

h2 {
font-size: 24px;
}

.student-form button {
font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
padding: 8px;
}
}
</style>
</head>
<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() {
// General message (success or info)
var message = [[${message}]] ? [[${message}]] : '';

// Error message
var errorMsg = [[${errorMsg}]] ? [[${errorMsg}]] : '';

if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'

123
});
}

if (errorMsg) {
Swal.fire({
title: 'Error',
text: errorMsg,
icon: 'error',
confirmButtonText: 'OK'
});
}
});
</script>
<body>
<div class="student-container">
<form class="student-form" th:action="@{/student/updateStudentProfile}" method="post"
th:object="${updateStudentProfileReq}">
<h2 class="full-width">Student Profile</h2>

<div class="form-group">
<label for="surname">Surname:</label>
<input type="text" id="surname" name="surname" th:field="*{surname}" required>
</div>

<div class="form-group">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" th:field="*{firstName}" required>
</div>

<div class="form-group">
<label for="genderId">Gender:</label>
<select id="genderId" name="genderId" th:field="*{gender}" th:value="*{genderId}" required>
<option value="" disabled selected>Select grade</option>
<option th:each="gender : ${genders}" th:value="${gender.genderId}"
th:text="${gender.gender}"></option>
</select>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" maxlength="10" th:field="*{mobile}" required>
</div>
<div class="form-group">
<label for="emailId">Email:</label>
<input type="text" id="emailId" name="emailId" th:field="*{emailId}" required>
</div>

<div class="form-group">
<label for="age">Age:</label>

124
<input type="text" id="age" name="age" maxlength="2" th:field="*{age}" required>
</div>
<div class="form-group">
<label for="gradeId">Grade:</label>
<select id="gradeId" name="gradeId" th:field="*{grade}" required>
<option value="" disabled selected>Select grade</option>
<option th:each="grade : ${grades}" th:value="${grade.gradeId}"
th:text="${grade.grade}"></option>

</select>
</div>
<div class="form-group">
<input type="hidden" id="userId" name="userId" th:field="*{userId}" required>
</div>
<div class="form-group full-width">
<button type="submit">Update</button>
</div>

<div class="form-group full-width">


<button type="button" onclick="window.location.href='/student/studentMenu'">Back to
Home</button>
</div>
</form>
</div>
</body>
</html>

HTML Template: Quiz

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Quiz Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 1200px;

125
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
display: flex;
flex-wrap: wrap;
margin-bottom: 15px;
}

.form-group label {
flex: 0 0 25%;
padding: 10px;
}

.form-group input,
.form-group select {
flex: 1;
padding: 10px;
margin-right: 10px;
}

.form-group input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
flex: 0 0 100%;
}

.form-group input[type="submit"]:hover {
background-color: #45a049;
}

.form-group button {
padding: 10px;
background-color: #f44336;
color: white;
border: none;
cursor: pointer;
}

.form-group button:hover {
background-color: #d32f2f;
}

126
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Icon button styling */


.icon-btn {
background-color: #f0f0f0; /* Light gray background */
border: 1px solid #ccc; /* Light border */
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333; /* Icon color */
transition: background-color 0.3s ease;
}

.icon-btn.edit {
color: #4CAF50; /* Green for edit */
}

.icon-btn.delete {
color: #f44336; /* Red for delete */
}

.icon-btn:hover {
background-color: #ddd; /* Slight background color change on hover */
}

/* Specific styling for IP Address and User ID */


.hidden-column {
font-size: 10px;
visibility: hidden;
}

127
/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
.form-group-back button:hover {
background-color: #45a049;
}
</style>

<script th:inline="javascript">
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
</script>
</head>
<body>
<div class="container">
<h1>Quiz Details</h1>
<div class="form-group-back">
<button type="button" onclick="window.location.href='/teacher/teacherMenu'">Back to
Home</button>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>S.No</th>
<th>Quiz Name</th>
<th>Teacher Name</th>

128
<th>Total Questions</th>
<th>Max Marks</th>
<th>Min Marks</th>
<th>Duration</th>
<th>Is Active</th>
<th>Created On</th>
</tr>
</thead>
<tbody>
<tr th:each="quiz,stat : ${quizzes}">
<td th:text="${stat.index + 1}"></td>
<td th:text="${quiz.quizName}"></td>
<td th:text="${quiz.teacherName}"></td>
<td th:text="${quiz.totalQuestions}"></td>
<td th:text="${quiz.maxMarks}"></td>
<td th:text="${quiz.minMarks}"></td>
<td th:text="${quiz.duration}"></td>
<td th:text="${quiz.isActive}"></td>
<td th:text="${#dates.format(quiz.transDate, 'dd-MM-yyyy')}"></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

HTML Template: StudentwisePerformance

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Student Wise Performance Details</title>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
/* Basic styling */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 1200px;

129
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
margin-bottom: 20px;
}
h2 {
text-align: center;
margin-bottom: 20px;
}

/* Form Group */
.form-group {
margin-bottom: 15px;
}

.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
/* Back Button */
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
transition: background-color 0.3s;
}

.form-group-back button:hover {
background-color: #45a049;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

130
th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Icon button styling */


.icon-btn {
background-color: #f0f0f0; /* Light gray background */
border: 1px solid #ccc; /* Light border */
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333; /* Icon color */
transition: background-color 0.3s ease;
}

.icon-btn.edit {
color: #4CAF50; /* Green for edit */
}

.icon-btn.delete {
color: #f44336; /* Red for delete */
}

.icon-btn:hover {
background-color: #ddd; /* Slight background color change on hover */
}

/* Specific styling for IP Address and User ID */


.hidden-column {
font-size: 10px;
visibility: hidden;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;

131
}
}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
.form-group-back button:hover {
background-color: #45a049;
}

.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
}

.pagination button {
padding: 10px;
margin: 0 5px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s;
}

.pagination button:disabled {
background-color: #ccc;
cursor: not-allowed;
}

.pagination span {
align-self: center;
margin: 0 10px;
}
#deleteButton {
width: 100%;
background-color: #ff4d4d; /* Red color */
color: white; /* Text color */
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 5px; /* Rounded corners */
transition: background-color 0.3s; /* Smooth transition */

132
}

</style>

<script>
$(document).ready(function() {
$('#studentSelect').change(function() {
var studentId = $(this).val();
// alert(studentId);
if (studentId) {
$.ajax({
url: '/teacher/topics/' + studentId,
method: 'GET',
success: function(data) {
var topicsBody = $('#topicsBody');
topicsBody.empty(); // Clear existing rows

$.each(data, function(index, topic) {

topicsBody.append('<tr>' +
'<td>' + (index + 1) + '</td>' +
'<td>' + topic.quizName + '</td>' +
'<td>' + topic.teacherName + '</td>' +
'<td>' + topic.totalQuestions + '</td>' +
'<td>' + topic.maxMarks + '</td>' +
'<td>' + topic.minMarks + '</td>' +
'<td>' + topic.duration + '</td>' +
'<td>' + new Date(topic.playDate).toLocaleDateString('en-GB') + '</td>' +
'<td>' + new Date(topic.startTime).toLocaleTimeString('en-GB') + '</td>' +
'<td>' + new Date(topic.endTime).toLocaleTimeString('en-GB') + '</td>' +
'<td>' + topic.accuracy + '</td>' +
'<td>' + topic.result + '</td>' +
'</tr>');
});
}
});
} else {
$('#topicsBody').empty(); // Clear if no student is selected
}
});
});

$(document).ready(function() {
const rowsPerPage = 10; // Set the number of rows per page
let currentPage = 1;
let topics = []; // Store the topics fetched from the server

$('#studentSelect').change(function() {
var studentId = $(this).val();
if (studentId) {

133
$.ajax({
url: '/teacher/topics/' + studentId,
method: 'GET',
success: function(data) {
topics = data; // Store the data for pagination
renderTable(); // Render the table with the first page
}
});
} else {
$('#topicsBody').empty(); // Clear if no student is selected
}
});

function renderTable() {
const start = (currentPage - 1) * rowsPerPage;
const end = start + rowsPerPage;
const paginatedTopics = topics.slice(start, end);

const topicsBody = $('#topicsBody');


topicsBody.empty(); // Clear existing rows

$.each(paginatedTopics, function(index, topic) {


topicsBody.append('<tr>' +
'<td>' + (start + index + 1) + '</td>' +
'<td>' + topic.quizName + '</td>' +
'<td>' + topic.teacherName + '</td>' +
'<td>' + topic.totalQuestions + '</td>' +
'<td>' + topic.maxMarks + '</td>' +
'<td>' + topic.minMarks + '</td>' +
'<td>' + topic.duration + '</td>' +
'<td>' + new Date(topic.playDate).toLocaleDateString('en-GB') + '</td>' +
'<td>' + new Date(topic.startTime).toLocaleTimeString('en-GB') + '</td>' +
'<td>' + new Date(topic.endTime).toLocaleTimeString('en-GB') + '</td>' +
'<td>' + topic.accuracy + '</td>' +
'<td>' + topic.result + '</td>' +
'</tr>');
});

updatePagination();
}

function updatePagination() {
$('#pageInfo').text(`Page ${currentPage} of ${Math.ceil(topics.length / rowsPerPage)}`);
$('#prevBtn').prop('disabled', currentPage === 1);
$('#nextBtn').prop('disabled', currentPage === Math.ceil(topics.length / rowsPerPage));
}

$('#prevBtn').click(function() {
if (currentPage > 1) {
currentPage--;
renderTable();
}

134
});

$('#nextBtn').click(function() {
if (currentPage < Math.ceil(topics.length / rowsPerPage)) {
currentPage++;
renderTable();
}
});
});

</script>

<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() {
var message = [[${message}]] ? [[${message}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
});

function deleteHighestScore() {
window.location.href = `/game/deleteHighestScore`;
}
</script>
</head>
<body>
<div class="container">
<h1>Student Performance Details</h1>
<div class="form-group-back">
<button type="button" onclick="window.location.href='/teacher/teacherMenu'">Back to
Home</button>
</div>
<div class="form-group">
<label></label>
</div>
<div class="form-group">
<button type="button" id="deleteButton" onclick="deleteHighestScore()">Delete Highest
Score</button>
</div>
<div class="form-group">
<label></label>
</div>
<div class="form-group">
<label for="studentSelect">Student:</label>
<select id="studentSelect" name="studentId">

<option value="" disabled selected>Select Student</option>

135
<option th:each="student : ${students}"
th:value="${student.studentId}"
th:text="${student.studentName}"></option>
</select>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>S.No</th>
<th>Topic-Quiz Name</th>
<th>Created By</th>
<th>Questions</th>
<th>Max M.</th>
<th>Min M.</th>
<th>Minutes</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>Accuracy</th>
<th>Result</th>
</tr>
</thead>
<tbody id="topicsBody">
<!-- Rows will be dynamically inserted here -->
</tbody>
</table>
<div class="pagination">
<button id="prevBtn" disabled>Previous</button>
<span id="pageInfo"></span>
<button id="nextBtn">Next</button>
</div>

</div>
<!--</div>-->
</body>
</html>

HTML Template: Teacher

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Teachers Details</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Add Font Awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
integrity="sha512-Fo3rlrZj/k6qn5olB6x8aTA6TpzD4A1L/5t+fdh8j9A+T9I1KuPiCMGrxQGq+lSklcq1Td/
wWc5qWm21ClxaGA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<style>
/* Basic styling */

136
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}

.container {
width: 100%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
display: flex;
flex-wrap: wrap;
margin-bottom: 15px;
}

.form-group label {
flex: 0 0 25%;
padding: 10px;
}

.form-group input,
.form-group select {
flex: 1;
padding: 10px;
margin-right: 10px;
}

.form-group input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
flex: 0 0 100%;
}

.form-group input[type="submit"]:hover {
background-color: #45a049;
}

.form-group button {

137
padding: 10px;
background-color: #f44336;
color: white;
border: none;
cursor: pointer;
}

.form-group button:hover {
background-color: #d32f2f;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
text-align: left;
}

th {
background-color: #4CAF50;
color: white;
}

/* Icon button styling */


.icon-btn {
background-color: #f0f0f0; /* Light gray background */
border: 1px solid #ccc; /* Light border */
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333; /* Icon color */
transition: background-color 0.3s ease;
}

.icon-btn.edit {
color: #4CAF50; /* Green for edit */
}

.icon-btn.delete {
color: #f44336; /* Red for delete */
}

138
.icon-btn:hover {
background-color: #ddd; /* Slight background color change on hover */
}

/* Specific styling for IP Address and User ID */


.hidden-column {
font-size: 10px;
visibility: hidden;
}

/* Responsive */
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;
}

.form-group input,
.form-group select {
flex: 1 0 100%;
}
}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
.form-group-back button:hover {
background-color: #45a049;
}
</style>

<script th:inline="javascript">
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
</script>
</head>
<body>
<div class="container">
<h1>Teachers Details</h1>

139
<div class="form-group-back">
<button type="button" onclick="window.location.href='/teacher/teacherMenu'">Back to
Home</button>
</div>
<table border="1">
<thead>
<tr>
<th>S.No</th>
<th>Surname</th>
<th>FirstName</th>
<th>Age</th>
<th>Gender</th>
<th>Email ID</th>
<th>Mobile No</th>
<th> Reg.Date </th>
<th>isActive</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr th:each="teacher, stat : ${teachers}">
<td th:text="${stat.index + 1}"></td>
<td th:text="${teacher.surName}"></td>
<td th:text="${teacher.firstName}"></td>
<td th:text="${teacher.age}"></td>
<td th:text="${teacher.gender}"></td>
<td th:text="${student.emailId}"></td>
<td th:text="${student.mobileNo}"></td>
<td th:text="${student.transDate}"></td>
<td th:text="${student.isActive} ? 'Yes' : 'No'"></td>
<td>
<a th:href="@{/students/edit/{id}(id=${teacher.teacherId})}">
<button class="icon-btn edit">
<i class="fas fa-edit"></i>
</button>
</a>
<a th:href="@{/students/delete/{id}(id=${teacher.teacherId})}" onclick="return confirm('Are
you sure?');">
<button class="icon-btn delete">
<i class="fas fa-trash"></i>
</button>
</a>
</td>
</tr>

</tbody>
</table>
</div>
</body>
</html>

140
HTML Template: TeacherMenu

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Teacher Home Page</title>
<link rel="stylesheet" th:href="@{/css/home.css}" />
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

.home-container {
width: 100%;
max-width: 600px;
margin: 40px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}

.home-form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 15px; /* Adding gap for consistent spacing */
}

.form-group {
flex: 1 1 48%;
margin-bottom: 15px;
}

.form-group.full-width {
flex: 1 1 100%;
}

.form-group button {
width: 100%;
padding: 12px;

141
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}

.form-group button:hover {
background-color: #45a049;
}

.user-name {
text-align: center;
font-size: 20px;
font-weight: bold;
color: #555;
margin-bottom: 20px;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.form-group {
flex: 1 1 100%;
margin-bottom: 10px;
}

.form-group button {
font-size: 14px;
padding: 10px;
}
}

@media (max-width: 480px) {


.home-container {
padding: 15px;
}

h2 {
font-size: 24px;
}

.form-group button {
font-size: 14px;
padding: 8px;
}
}

@media (max-width: 360px) {


.form-group button {
font-size: 12px;
padding: 6px;
}

142
}
</style>
</head>
<body>
<div class="home-container">
<form class="home-form">
<div class="user-name" th:text="'Welcome, ' + ${userName} + ' '"></div>
<div class="form-group full-width">
<h2>Main Menu</h2>
</div>
<div class="form-group">
<button type="button" onclick="window.location.href='/quizs'">Quiz Info</button>
</div>

<!-- 2-column layout buttons -->


<div class="form-group">
<button type="button" onclick="window.location.href='/teacher/question'">Questions
Info</button>
</div>
<div class="form-group">
<button type="button"
onclick="window.location.href='/teacher/studentWisePerformance'">Student Performance</button>
</div>
<div class="form-group">
<button type="button" onclick="window.location.href='/user/loginHistory'">Login
History</button>
</div>

<!-- Password & Logout -->


<div class="form-group">
<button type="button" onclick="window.location.href='/user/changePassword'">Change
Password</button>
</div>
<div class="form-group">
<button type="button" onclick="window.location.href='/teacher/updateTeacherProfile'">Update
Profile</button>
</div>
<div class="form-group full-width">
<button type="button" onclick="window.location.href='/user/logOut'">Logout</button>
</div>

</form>
</div>
</body>
</html>

HTML Template: UpdateTeacherProfile

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

143
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Profile Details Page</title>
<link rel="stylesheet" th:href="@{/css/login.css}" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

.teacher-container {
width: 100%;
max-width: 600px;
margin: auto;
background-color: white;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}

.teacher-form {
display: flex;
flex-wrap: wrap;
}

.form-group {
flex: 0 0 48%;
margin: 10px 1%;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}

.form-group label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}

.teacher-form button {
width: 100%;
padding: 15px;

144
margin-top: 20px;
background-color: #4CAF50;
border: none;
color: white;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}

.teacher-form button:hover {
background-color: #45a049;
}

.full-width {
flex: 0 0 100%;
}

h2 {
text-align: center;
width: 100%;
margin-bottom: 20px;
}

.radio-group {
display: flex;
gap: 10px;
padding: 10px 0;
}

.radio-group input {
margin-right: 5px;
}

/* Modal styles */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}

.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;

145
width: 80%;
max-width: 300px;
text-align: center;
}

.modal-content button {
padding: 10px 20px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;
}

.modal-content button:hover {
background-color: #45a049;
}

.error-message {
color: red;
}

/* Responsive Styles */
@media (max-width: 768px) {
.form-group {
flex: 0 0 100%;
margin: 10px 0;
}

.teacher-form button {
padding: 12px;
font-size: 14px;
}

.radio-group {
flex-direction: column;
align-items: flex-start;
}
}

@media (max-width: 480px) {


.teacher-container {
padding: 15px;
}

h2 {
font-size: 24px;
}

.teacher-form button {
font-size: 14px;
}

146
.form-group input[type="text"],
.form-group input[type="password"] {
padding: 8px;
}
}
</style>
<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() {
// General message (success or info)
var message = [[${message}]] ? [[${message}]] : '';

// Error message
var errorMsg = [[${errorMsg}]] ? [[${errorMsg}]] : '';

if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}

if (errorMsg) {
Swal.fire({
title: 'Error',
text: errorMsg,
icon: 'error',
confirmButtonText: 'OK'
});
}
});
</script>
</head>
<body>
<div class="teacher-container">
<form class="teacher-form" th:action="@{/teacher/updateTeacherProfile}" method="post"
th:object="${updateTeacherProfileReq}">
<h2 class="full-width">Teacher Profile</h2>
<div class="form-group">
<label for="surname">Surname:</label>
<input type="text" id="surname" name="surname" th:field="*{surname}" required>
</div>

<div class="form-group">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" th:field="*{firstName}" required>
</div>
<div class="form-group">

147
<label for="genderId">Gender:</label>
<select id="genderId" name="genderId" th:field="*{gender}" th:value="*{genderId}" required>
<option value="" disabled selected>Select grade</option>
<option th:each="gender : ${genders}" th:value="${gender.genderId}"
th:text="${gender.gender}"></option>
</select>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" maxlength="10" th:field="*{mobile}" required>
</div>
<div class="form-group">
<label for="emailId">Email:</label> <input type="text" id="emailId" name="emailId"
th:field="*{emailId}" required>
</div>

<div class="form-group">
<label for="age">Age:</label>
<input type="text" id="age" name="age" maxlength="2" th:field="*{age}" required>
</div>
<div class="form-group full-width">
<button type="submit">Update</button>
</div>

<div class="form-group full-width">


<button type="button" onclick="window.location.href='/teacher/teacherMenu'">Back to
Home</button>
</div>
</form>
</div>
</body>
</html>

HTML Template: Login

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet" th:href="@{/css/login.css}" />
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}

148
.login-container {
width: 100%;
max-width: 400px;
margin: 40px auto;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}

.radio-group {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
}

.radio-group label {
margin-right: 10px;
}

.form-group {
margin-bottom: 15px;
}

.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}

.form-group input[type="text"],
.form-group input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}

.form-group button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;

149
border-radius: 5px;
font-size: 16px;
}

.form-group button:hover {
background-color: #45a049;
}

/* Responsive Styles */
@media (max-width: 768px) {
.radio-group {
flex-direction: column;
align-items: flex-start;
}

.radio-group label {
margin-bottom: 10px;
}

.form-group button {
font-size: 14px;
}
}

@media (max-width: 480px) {


.login-container {
padding: 15px;
margin-top: 20px;
}

h2 {
font-size: 24px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
padding: 8px;
}
}
</style>
<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() {
var message = [[${errorMsg}]] ? [[${errorMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
});

150
</script>
</head>
<body>
<div class="login-container">
<form class="login-form" th:action="@{/user/login}" method="post" th:object="${user}">
<h2>Login Here</h2>
<div class="radio-group">
<label><input type="radio" name="usertype" value="1" th:field="*{userTypeId}" required>
Student</label>
<label><input type="radio" name="usertype" value="3" th:field="*{userTypeId}" required>
Teacher</label>
</div>
<div class="form-group">
<label for="username">Username or Email</label>
<input type="text" id="username" name="username" th:field="*{email}" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" th:field="*{password}" required>
</div>
<div class="form-group">
<button type="submit">Login</button>
</div>
<div class="form-group">
<button type="button" onclick="window.location.href='/user/signUp'">Sign Up</button>
</div>
</form>
</div>
</body>
</html>

HTML Template: SignUp

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Page</title>
<link rel="stylesheet" th:href="@{/css/login.css}" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

.register-container {
width: 100%;

151
max-width: 600px;
margin: auto;
background-color: white;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}

.register-form {
display: flex;
flex-wrap: wrap;
}

.form-group {
flex: 0 0 48%;
margin: 10px 1%;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}

.form-group label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}

.register-form button {
width: 100%;
padding: 15px;
margin-top: 20px;
background-color: #4CAF50;
border: none;
color: white;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}

.register-form button:hover {
background-color: #45a049;
}

.full-width {
flex: 0 0 100%;

152
}

h2 {
text-align: center;
width: 100%;
margin-bottom: 20px;
}

.radio-group {
display: flex;
gap: 10px;
padding: 10px 0;
}

.radio-group input {
margin-right: 5px;
}

/* Modal styles */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}

.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 300px;
text-align: center;
}

.modal-content button {
padding: 10px 20px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;
}

.modal-content button:hover {

153
background-color: #45a049;
}

.error-message {
color: red;
}

/* Responsive Styles */
@media (max-width: 768px) {
.form-group {
flex: 0 0 100%;
margin: 10px 0;
}

.register-form button {
padding: 12px;
font-size: 14px;
}

.radio-group {
flex-direction: column;
align-items: flex-start;
}
}

@media (max-width: 480px) {


.register-container {
padding: 15px;
}

h2 {
font-size: 24px;
}

.register-form button {
font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
padding: 8px;
}
}
</style>
<script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() {
// General message (success or info)
var message = [[${message}]] ? [[${message}]] : '';

// Error message
var errorMsg = [[${errorMsg}]] ? [[${errorMsg}]] : '';

154
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}

if (errorMsg) {
Swal.fire({
title: 'Error',
text: errorMsg,
icon: 'error',
confirmButtonText: 'OK'
});
}
});
</script>
</head>
<body>
<div class="register-container">
<form class="register-form" th:action="@{/user/signUp}" method="post"
th:object="${userSignUpReq}">
<h2 class="full-width">Sign Up Here</h2>

<div class="form-group full-width">


<label for="userTypeId">User Type:</label>
<div class="radio-group">
<label><input type="radio" name="userTypeId" value= "1" required> Student</label>
<label><input type="radio" name="userTypeId" value= "3" required> Teacher</label>
</div>
</div>

<div class="form-group">
<label for="surname">Surname:</label>
<input type="text" id="surname" name="surname" required>
</div>

<div class="form-group">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" required>
</div>

<div class="form-group">
<label for="genderId">Gender:</label>
<select id="genderId" name="genderId" required>
<option value="" disabled selected>Select gender</option>
<option value="1">Male</option>
<option value="2">Female</option>

155
<option value="3">Other</option>
</select>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" maxlength="10" required>
</div>
<div class="form-group full-width">
<label for="email">Email:</label>
<input type="text" id="email" name="email" required>
</div>

<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>

<div class="form-group">
<label for="confirmpassword">Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" required>
</div>

<div class="form-group full-width">


<button type="submit">Sign Up</button>
</div>

<div class="form-group full-width">


<button type="button" onclick="window.location.href='/user/login'">Login</button>
</div>
</form>
</div>
</body>
</html>

CSS: Login

body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.login-container {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

156
.login-form {
max-width: 300px;
margin: 0 auto;
}

.login-form h2 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
margin-bottom: 15px;
}

.form-group label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}

.form-group input {
width: 100%;
padding: 8px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}

button[type="submit"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}

button[type="submit"]:hover {
background-color: #45a049;
}
button[type="button"] {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;

157
}
button[type="button"]:hover {
background-color: #45a049;
}

CSS: Styles

body {
font-family: Arial, sans-serif;
background-color: #f0f8ff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;}
form {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 800px;
display: flex;
flex-direction: column;
align-items: center;}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
width: 50%;
text-align: left;}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
width: 50%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;}
input[type="radio"],
input[type="checkbox"] {
margin-right: 5px;}
.radio-group {
display: flex;
justify-content: space-between;
width: 50%;
margin-bottom: 10px;}
button {
background-color: #4CAF50;
color: white;

158
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
width: 50%;
margin-bottom: 10px;}
button:hover {
background-color: #45a049;}
button[type="button"] {
background-color: #008CBA;}
button[type="button"]:hover {
background-color: #007bb5;}
p{
color: green;
font-weight: bold;}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 300px;
text-align: center;}
.modal-content button {
padding: 10px 20px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;}
.modal-content button:hover {
background-color: #45a049;}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;}
.login-container {
width: 100%;
max-width: 400px;
margin: 40px auto;

159
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);}
h2 {
text-align: center;
margin-bottom: 20px;
color: #333;}
.radio-group {
display: flex;
justify-content: space-around;
margin-bottom: 20px;}
.radio-group label {
margin-right: 10px;}
.form-group {
margin-bottom: 15px;}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;}
.form-group input[type="text"],
.form-group input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;}
.form-group button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;}
.form-group button:hover {
background-color: #45a049;}
.radio-group label {
margin-bottom: 10px;}
.form-group button {
font-size: 14px;}
h2 {
font-size: 24px;}
.form-group input[type="text"],
.form-group input[type="password"] {
padding: 8px;}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;}

160
.login-container {
width: 100%;
max-width: 600px;
margin: auto;
background-color: white;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;}
.register-form {
display: flex;
flex-wrap: wrap;}
.form-group {
flex: 0 0 48%;
margin: 10px 1%;}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;}
.form-group label {
display: block;
font-weight: bold;
margin-bottom: 5px;}
.register-form button {
width: 100%;
padding: 15px;
margin-top: 20px;
background-color: #4CAF50;
border: none;
color: white;
cursor: pointer;
border-radius: 5px;
font-size: 16px;}
.register-form button:hover {
background-color: #45a049;}
.full-width {
flex: 0 0 100%;}
h2 {
text-align: center;
width: 100%;
margin-bottom: 20px;}
.radio-group {
display: flex;
gap: 10px;
padding: 10px 0;}
.radio-group input {
margin-right: 5px;}
.modal {
display: none;

161
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 300px;
text-align: center;}
.modal-content button {
padding: 10px 20px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;}
.modal-content button:hover {
background-color: #45a049;}
.error-message {
color: red;}
.register-form button {
padding: 12px;
font-size: 14px;}
.radio-group {
flex-direction: column;
align-items: flex-start;}
.register-form button {
font-size: 14px;}
.login-container {
width: 100%;
max-width: 600px;
margin: 40px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);}
.home-form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;}
.form-group {
width: 48%;
margin-bottom: 15px;}
.full-width {

162
width: 100%;}
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;}
.container {
width: 100%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);}
h2 {
text-align: center;
margin-bottom: 20px;}
.form-group {
display: flex;
flex-wrap: wrap;
margin-bottom: 15px;}
.form-group label {
flex: 0 0 25%;
padding: 10px;}
.form-group input,
.form-group select {
flex: 1;
padding: 10px;
margin-right: 10px;}
.form-group input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
flex: 0 0 100%;}
.form-group input[type="submit"]:hover {
background-color: #45a049;}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;}
.form-group-back button:hover {
background-color: #45a049;}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;}
table, th, td {

163
border: 1px solid #ddd;}
th, td {
padding: 12px;
text-align: left;}
th {
background-color: #4CAF50;
color: white;}
.icon-btn {
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
padding: 8px;
margin: 0 5px;
cursor: pointer;
font-size: 18px;
display: inline-block;
color: #333;
transition: background-color 0.3s ease;}
.icon-btn.edit {
color: #4CAF50;
.icon-btn.delete {
color: #f44336;
.icon-btn:hover {
background-color: #ddd;
.hidden-column {
font-size: 10px;
visibility: hidden;}
.form-group input,
.form-group select {
flex: 1 0 100%;}
.home-container {
width: 100%;
max-width: 600px;
margin: 40px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);}
.home-form {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 15px; /* Adding gap for consistent spacing */}
.form-group {
flex: 1 1 48%;
margin-bottom: 15px;}
.form-group.full-width {
flex: 1 1 100%;}
.form-group button {
width: 100%;
padding: 12px;
background-color: #4CAF50;

164
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;}
.user-name {
text-align: center;
font-size: 20px;
font-weight: bold;
color: #555;
margin-bottom: 20px;}
.form-group button {
font-size: 14px;
padding: 10px;}
.form-group button {
padding: 10px;
background-color: #f44336;
color: white;
border: none;
cursor: pointer;}
.form-group button:hover {
background-color: #d32f2f;}
h1 {
text-align: center;
margin-bottom: 20px;}
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;}
.form-group-back button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
transition: background-color 0.3s;}
.pagination {
display: flex;
justify-content: center;
margin-top: 20px;}
.pagination button {
padding: 10px;
margin: 0 5px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
border-radius: 5px;

165
transition: background-color 0.3s;}
.pagination button:disabled {
background-color: #ccc;
cursor: not-allowed;}
.pagination span {
align-self: center;
margin: 0 10px;}
.container {
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;}
.form-group-back button {
font-size: 14px;
padding: 10px;}
.pagination {
margin-top: 20px;
text-align: center;
display: flex;
justify-content: center;
align-items: center;}
.pagination a, .pagination span {
color: white;
padding: 10px 20px;
text-decoration: none;
margin: 0 5px;
border: 1px solid #4CAF50;
background-color: #4CAF50;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;}
.pagination a.disabled {
background-color: #ddd;
color: #888;
cursor: not-allowed;}
.pagination span {
background-color: #4CAF50;
cursor: default;}
.pagination a:hover:not(.disabled) {
background-color: #45a049;}
.form-group input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;}
.container {

166
width: 100%;
max-width: 500px;
margin: 40px auto;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);}
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;}
.form-group select {
padding: 8px;}
#playButton:disabled {
background-color: #ccc; /* Gray color for disabled state */
color: #666; /* Faded text color */
cursor: not-allowed; /* Change cursor to indicate it's not clickable */}
#playButton {
background-color: #007bff; /* Primary color */
color: white; /* Text color */
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 5px; /* Rounded corners */
transition: background-color 0.3s; /* Smooth transition */}
#playButton:hover:not(:disabled) {
background-color: #0056b3; /* Darker shade on hover */}
@media screen and (max-width: 768px) {
th, td {
font-size: 14px;
padding: 8px;}
@media (max-width: 480px) {
.home-container {
padding: 15px;}
.form-group button {
font-size: 14px;
padding: 8px;}
@media (max-width: 360px) {
.form-group button {
font-size: 12px;
padding: 6px;}
@media (max-width: 768px) {
.form-group {
width: 100%;
margin-bottom: 10px;}
@media (max-width: 768px) {
.radio-group {
flex-direction: column;
align-items: flex-start;}

167
@media (max-width: 480px) {
.login-container {
padding: 15px;
margin-top: 20px;}
@media (max-width: 768px) {
.form-group {
flex: 0 0 100%;
margin: 10px 0;}
@media (max-width: 480px) {
.login-container {
padding: 15px;}
@media screen and (max-width: 768px) {
.form-group label {
flex: 0 0 100%;}
@media (max-width: 768px) {
.form-group {
flex: 1 1 100%;
margin-bottom: 10px;}
@media (max-width: 768px) {
.form-group button {
font-size: 14px;}
@media (max-width: 480px) {
.container {
padding: 15px;
margin-top: 20px;}

JS: Validation

document.addEventListener("DOMContentLoaded", function() {
const form = document.querySelector("form");
const password = document.querySelector("input[name='password']");
const reenterPassword = document.querySelector("input[name='reenterPassword']");
const errorMessage = document.createElement("p");
errorMessage.style.color = "red";

form.addEventListener("submit", function(event) {
if (password.value !== reenterPassword.value) {
errorMessage.textContent = "Passwords do not match";
form.insertBefore(errorMessage, form.querySelector("button[type='submit']"));
event.preventDefault();
} else if (!/^(?=.*[0-9])(?=.*[!@#$%^&*]).{8,}$/.test(password.value)) {
errorMessage.textContent = "Password must be at least 8 characters long, contain at least one
numeric and one special character";
form.insertBefore(errorMessage, form.querySelector("button[type='submit']"));
event.preventDefault();
} else {
errorMessage.textContent = "";
}
});
});

JS: Common

168
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}

document.addEventListener("DOMContentLoaded", function() {
var message = [[${delMsg}]] ? [[${delMsg}]] : '';
if (message) {
Swal.fire({
title: 'Message',
text: message,
icon: 'info',
confirmButtonText: 'OK'
});
}
});
$(document).ready(function() {
$('#topicName').change(function() {
var topicId = $(this).val();
if (topicId) {
$.ajax({
url: '/game/quizzes/' + topicId,
method: 'GET',
success: function(data) {
var quizList = $('#quizList');
quizList.empty(); // Clear existing options
quizList.append('<option value="" disabled selected>Select Quiz</option>'); // Add
default option

$.each(data, function(index, quiz) {


quizList.append('<option value="' + quiz.quizId + '">' + quiz.quizName + '</option>');
});
},
error: function() {
alert("Failed to fetch quizzes. Please try again.");
}
});
} else {
$('#quizList').empty(); // Clear if no topic is selected
$('#quizList').append('<option value="" disabled selected>Select Quiz</option>'); // Add
default option
}
});
});
function checkSelection() {
const topicSelect = document.getElementById('topicName');

169
const quizSelect = document.getElementById('quizList');
const playButton = document.getElementById('playButton');

// Enable the button if both selections are made


if (topicSelect.value && quizSelect.value) {
playButton.disabled = false;
} else {
playButton.disabled = true;
}
}

function playGame() {
const quizSelect = document.getElementById('quizList');
const selectedQuizId = quizSelect.value;

// Redirect to the game page with the selected quiz ID


window.location.href = `/game/game/`+selectedQuizId;
}

Stored Procedure: ImpQueries

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[ImpQueries] Script Date: 11/30/2024 8:16:49 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[ImpQueries]
AS
BEGIN
SELECT * FROM DifficultyLevel
SELECT * FROM ErrorLog
SELECT * FROM GenderMaster
SELECT * FROM GradeMaster
SELECT * FROM LoginHistory
SELECT * FROM QuestionSet
SELECT QuizId,count(*) FROM QuestionSet GROUP BY QuizId ORDER BY QuizId
SELECT * FROM QuestionSet WHERE QuizID IN (15)--7>>11,9>>9,15>>>8
--UPDATE QuestionSet SET UserId=1
SELECT * FROM Quiz
--UPDATE Quiz SET UserId=1
SELECT * FROM Student
SELECT * FROM StudentPerformanceDetails
SELECT * FROM Teacher
SELECT * FROM TopicDetails
SELECT * FROM UserDetails
SELECT * FROM UserType

170
SELECT * FROM QuestionSet WHERE QuizID IN (15)--7>>11,9>>9,15>>>8

--select distinct local_net_address, local_tcp_port from sys.dm_exec_connections where


local_net_address is not null

SELECT QuizId, QuizName, TeacherId, TopicId, LevelId, TotalQuestions, MaxMarks,


MinMarks, Duration, isActive, IPAddress, TransDate, UserId FROM Quiz

SELECT QuestionId, QuizId, questionDescription, questionHint, optionA, optionB, optionC,


optionD, optionE, Answer, isActive, IPAddress, TransDate, UserId FROM QuestionSet

SELECT * FROM QuestionSet WHERE questionDescription Like '%What is the median of


this dataset?%'
END

Stored Procedure: LoginInfo

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[LoginInfo] Script Date: 11/30/2024 8:17:58 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[LoginInfo]
​ @IMode​ ​ ​ char (3),
​ @IUserId​ ​ INT​ =​ NULL,
​ @IUserTypeId​​ INT​ =​ NULL,
​ @ILoginId​ ​ ​ VARCHAR(50)​ ​ ​ =​ NULL,
​ @IPwd​​ ​ VARCHAR(50)​ =​ NULL,
​ @IIPAddress​ ​ VARCHAR(15)​ =​ NULL,
​ @StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
​ AS
​ BEGIN
​ SET NOCOUNT ON

​ IF @IMode='LOG'---Login User
​ BEGIN
​ IF EXISTS(SELECT LoginId from UserDetails where LoginId= @ILoginId and
Deactive=1 AND UserTypeId=@IUserTypeId)
​ BEGIN
​ ​ SET @StrResult= 'User is inactive, please contact your administrator!'
​ ​ RETURN
​ END

171
​ IF NOT EXISTS(SELECT LoginId from UserDetails where LoginId= @ILoginId AND
UserTypeId=@IUserTypeId)
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Invalid Login Id, please try again!'
​ ​ ​ RETURN
​ ​ END

​ ​ IF NOT EXISTS(SELECT LoginId from UserDetails where LoginId=


@ILoginId and Pwd=@IPwd and Deactive=0 AND UserTypeId=@IUserTypeId)
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Invalid credentials, please try again!'
​ ​ ​ RETURN
​ ​ END

​ ​ BEGIN TRY
​ ​ ​ BEGIN TRANSACTION
​ ​ ​ ​ Update UserDetails SET
​ ​ ​ ​ LoginDate=getDate(),
​ ​ ​ ​ IPAddress=@IIPAddress,
​ ​ ​ ​ CNT=0,
​ ​ ​ ​ Deactive=0,
​ ​ ​ ​ DACTIVE_TIME=NULL
​ ​ ​ ​ where LoginId=@ILoginId AND UserTypeId=@IUserTypeId

​ ​ ​ ​ DECLARE @MyUserId AS INT=1


​ ​ ​ ​ SELECT @MyUserId=UserId from UserDetails WHERE
LoginId=@ILoginId AND UserTypeId=@IUserTypeId AND Deactive=0

​ ​ ​ ​ INSERT INTO LoginHistory(LoginId, Password, UserTypeId,


LoginDate, LogoutDate, totalDuration, IPAddress, Success, UserId)
​ ​ ​ ​ ​ ​ ​ ​ values (@ILoginId, @IPwd,
@IUserTypeId, getDate(), NULL, NULL, @IIPAddress, 'S', @MyUserId)

​ ​ ​ ​ SET @StrResult = 'SUCCESS'


​ ​ ​ ​ ​ ​ ​ ​
​ ​ ​ COMMIT TRANSACTION
​ ​ ​ END TRY
​ ​ ​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN Error_Message()
​ ​ ​ END CATCH
​ END

​ IF @IMode='UID'--GET login UserId
​ BEGIN
​ ​ SELECT UserId from UserDetails WHERE LoginId=@ILoginId AND
UserTypeId=@IUserTypeId AND Deactive=0
​ END

172
​ IF @IMode='LUN' --GET login UserName
​ BEGIN
​ ​ --SELECT A.FirstName +' ('+B.UserTypeName+')' AS UserName
​ ​ SELECT A.FirstName AS UserName
​ ​ from UserDetails​ A
​ ​ --INNER JOIN UserType​ B ON B.UserTypeId=A.UserTypeId ​ ​
​ ​ WHERE A.LoginId=@ILoginId AND A.UserTypeId=@IUserTypeId AND
Deactive=0
​ END

​ IF @IMode='HIS' --Login History
​ BEGIN
​ ​ SELECT TOP 20 B.FirstName,A.LoginId, A.Password, C.UserTypeName,
A.LoginDate, A.LogoutDate, ISNULL(A.totalDuration,0) AS totalDuration --, Success ,
IPAddress
​ ​ FROM LoginHistory​ ​ A
​ ​ INNER JOIN UserDetails​ B on B.UserTypeId=A.UserTypeId AND
B.UserId =A.UserId
​ ​ INNER JOIN UserType​ ​ C on C.UserTypeId=A.UserTypeId
​ ​ WHERE A.UserId=@IUserId
​ ​ ORDER BY A.LoginHistoryId DESC
​ END
​ IF @IMode='UPD' --Change Password
​ BEGIN
​ IF EXISTS(SELECT LoginId from UserDetails where LoginId= @ILoginId and
Deactive=1)
​ BEGIN
​ ​ SET @StrResult= 'User is inactive, please contact your administrator!'
​ ​ RETURN
​ END

​ IF NOT EXISTS(SELECT LoginId from UserDetails where LoginId= @ILoginId)


​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Invalid Login Id, please try again!'
​ ​ ​ RETURN
​ ​ END
​ ​ DECLARE @MyPwd AS VARCHAR(50)​
​ ​ SELECT @MyPwd=Pwd from UserDetails where LoginId= @ILoginId

​ ​ IF @IPwd=@MyPwd
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'New Password and Old Password must not be
same'
​ ​ ​ RETURN
​ ​ END
​ ​ IF LEN(@IPwd) < 8
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Password must be at least 8 character long'

173
​ ​ ​ RETURN
​ ​ END
​ ​ UPDATE UserDetails SET Pwd = @IPwd,ChangePasswordDate=GETDATE()
where LoginId=@ILoginId AND Deactive=0
​ ​ SET @StrResult= 'SUCCESS'
​ END

​ IF @IMode='OUT' ---LogOut
​ ​ BEGIN
​ ​ ​ UPDATE LoginHistory SET LogoutDate= getDate(),totalDuration =
DATEDIFF(mi,LoginDate,getDate()) WHERE UserId= RTRIM(LTRIM(@IUserId)) AND
UserTypeId =@IUserTypeId and LogoutDate is NULL
​ ​ ​ and LoginHistoryId=(SELECT MAX(LoginHistoryId) from LoginHistory
where UserId= RTRIM(LTRIM(@IUserId)) AND UserTypeId =@IUserTypeId)
​ ​ ​ SET @StrResult = 'SUCCESS'
​ ​ ​ END
​ END

Stored Procedure: PlayGame

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[PlayGame] Script Date: 11/30/2024 8:19:15 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER​ proc [dbo].[PlayGame]
(​
​ @Mode​ ​ ​ CHAR(3)​ ​ =​ NULL,
​ @IQuizId​ ​ INT​ ​ ​ =​ NULL,
​ @ICorrectAns​INT​ ​ ​ =​ NULL,
​ @IUserId​ ​ INT​ ​ ​ =​ NULL,
​ @IIPAddress​ ​ VARCHAR(15) ​ =​ NULL,
​ @StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
DECLARE @MyStudentId AS INT=0
if (@Mode= 'INS') ---Start Game
BEGIN
​ if exists(select UserId from UserDetails where UserId= @IUserId And UserTypeId=3)
​ BEGIN
​ ​ SET @StrResult='Teacher are not allowed to play game'
​ ​ RETURN
​ END

174
​ if exists(select UserId from UserDetails where UserId= @IUserId And UserTypeId=1
AND Deactive=1)
​ BEGIN
​ ​ SET @StrResult='User Deactivated not allowed to play game'
​ ​ RETURN
​ END

​ SELECT @MyStudentId=StudentId FROM Student WHERE UserId= @IUserId

​ DECLARE @MyTopicId AS INT=0


​ DECLARE @MyLevelId AS INT=0
​ SELECT @MyTopicId=TopicId,@MyLevelId=LevelId FROM Quiz WHERE QuizId=
@IQuizId
​ if @MyStudentId=0
​ BEGIN
​ ​ SET @StrResult='Invalid User not allowed to play game'
​ ​ RETURN
​ END

​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ INSERT INTO StudentPerformanceDetails(StudentId,TopicId,LevelId,
QuizId , Accuracy, Result, StartTime, EndTime, TotalDuration,isTrophy,isCertificate,
IPAddress, TransDate,UserId)
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​
values(@MyStudentId,@MyTopicId,@MyLevelId, @IQuizId, NULL, NULL, GETDATE(),
NULL, NULL,'N','N', @IIPAddress, GETDATE(),@IUserId)
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END
​ if (@Mode= 'UPD') ---End Game
BEGIN

​ DECLARE @MyTotalQuestions AS INT=0
​ SELECT @MyTotalQuestions=TotalQuestions FROM Quiz WHERE QuizId=
@IQuizId

​ DECLARE @MyResult AS VARCHAR='Fail'


​ IF @ICorrectAns>=6
​ BEGIN
​ SET @MyResult='Pass'
​ END

175
​ DECLARE @MyAccuracy AS VARCHAR(10)='N/A'
​ SET @MyAccuracy= CAST(@ICorrectAns AS
VARCHAR)+'/'+CAST(@MyTotalQuestions AS VARCHAR)


​ SELECT @MyStudentId=StudentId FROM Student WHERE UserId= @IUserId
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE StudentPerformanceDetails SET
​ ​ ​ ​ ​ ​ Accuracy=@MyAccuracy,
​ ​ ​ ​ ​ ​ Result=@MyResult,
​ ​ ​ ​ ​ ​ EndTime=GETDATE(),
​ ​ ​ ​ ​ ​
TotalDuration=DATEDIFF(mi,StartTime,getDate()) ,
​ ​ ​ ​ ​ ​ isTrophy=CASE WHEN @ICorrectAns>=8
THEN 'Y' ELSE 'N'END,
​ ​ ​ ​ ​ ​ isCertificate=CASE WHEN
@ICorrectAns=@MyTotalQuestions THEN 'Y' ELSE 'N'END
​ ​ ​ ​ ​ ​ WHERE StudentId=@MyStudentId AND
QuizId= @IQuizId AND UserId =@IUserId AND EndTime IS NULL
​ ​ ​ ​ ​ ​ AND PId=(SELECT MAX(PId) FROM
StudentPerformanceDetails WHERE StudentId=@MyStudentId AND QuizId=@IQuizId AND
UserId =@IUserId)

​ ​ ​ ​ ​ ​
​ ​ ​ ​ ​ ​ DECLARE @MyTotTrophy AS INT=0
​ ​ ​ ​ ​ ​ DECLARE @MyTotCertificate AS INT=0
​ ​ ​ ​ ​ ​ SELECT @MyTotTrophy​ ​ =​
COUNT(Pid) FROM StudentPerformanceDetails WHERE StudentId=@MyStudentId AND
isTrophy='Y'
​ ​ ​ ​ ​ ​ SELECT @MyTotCertificate​ =​
COUNT(Pid) FROM StudentPerformanceDetails WHERE StudentId=@MyStudentId AND
isCertificate='Y'
​ ​ ​ ​ ​ ​ UPDATE Student SET
TotalTrophies=@MyTotTrophy,TotalCertificates=@MyTotCertificate WHERE
StudentId=@MyStudentId
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END

END

176
Stored Procedure: QuestionInfo

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[QuestionInfo] Script Date: 11/30/2024 8:19:38 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[QuestionInfo]
(
@IMode​ CHAR(3),
@IQuizId​ ​ INT​ =​ NULL,
@IQuestionId​ INT​ = NULL,
@IQuestionDescription​ VARCHAR(MAX)​ =​ NULL,
@IQuestionHint​ ​ VARCHAR(50)​ ​ =​ NULL,
@IOptionA​ ​ VARCHAR(20)​ =​ NULL,
@IOptionB​ ​ VARCHAR(20)​ =​ NULL,
@IOptionC​ ​ VARCHAR(20)​ =​ NULL,
@IOptionD​ ​ VARCHAR(20)​ =​ NULL,
@IOptionE​ ​ VARCHAR(20)​ =​ NULL,
@IAnswer​ ​ CHAR(1)​ =​ NULL,
@IisActive​ ​ BIT​ =​ NULL,
@IIPAddress​ VARCHAR(15)​ =​ NULL,
@IUserId​ INT​ =​ NULL,
@StrResult​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
​ SET NOCOUNT ON
​ DECLARE @MyMaxMarks AS INT=0
​ DECLARE @MyMinMarks AS INT=0
​ DECLARE @MyDuration AS INT=0
​ DECLARE @MyCnt AS INT=0

​ IF @IMode='DD1' --List of topics


​ BEGIN
​ ​ SELECT TopicId, TopicName FROM TopicDetails WHERE isActive=1
​ END

​ IF @IMode='DD2'
​ BEGIN
​ ​ SELECT A.QuizId, A.QuizName+' : Created By '+B.FirstName +' ,Total No
Questions '+CAST(A.TotalQuestions AS VARCHAR) +' ,Max Marks '+CAST(A.MaxMarks AS
VARCHAR)+' ,Duration '+CAST(A.Duration AS VARCHAR)+' Seconds/Question ' AS
QuizName
​ ​ FROM Quiz A
​ ​ INNER JOIN Teacher B ON B.TeacherId=A.TeacherId

177
​ ​ WHERE A.isActive=1 --AND A.UserId=@IUserId
​ END​


​ IF @IMode='DD3' --List of Difficulty levels
​ BEGIN
​ ​ SELECT LevelId, LevelName FROM DifficultyLevel WHERE isActive=1
​ END

​ IF @IMode='MST' --List of Difficulty levels


​ BEGIN
​ ​ SELECT TotalQuestions AS TotQ,Duration AS
DurationPerQ,Duration*TotalQuestions/60 AS TotDuration FROM Quiz WHERE
QuizId=@IQuizId
​ END

​ IF @IMode='DG1'
​ BEGIN
​ ​ SELECT A.QuestionId, A.QuizId,A.questionDescription, A.questionHint,
A.optionA, A.optionB, A.optionC, A.optionD,A.optionE, A.Answer,
​ ​ A.TransDate,A.isActive, A.UserId
​ ​ FROM QuestionSet A
​ ​ WHERE --A.UserId= @IUserId AND
​ ​ A.QuizId = @IQuizId AND A.isActive=1​ ​
​ END

​ IF @IMode='DG2'
​ BEGIN
​ ​ SELECT A.QuestionId, A.QuizId,A.questionDescription, A.questionHint,
A.optionA, A.optionB, A.optionC, A.optionD,A.optionE, A.Ans AS Answer,A.QSno,
​ ​ A.TransDate,A.isActive, A.UserId
​ ​ FROM QuestionSet A
​ ​ WHERE --A.UserId= @IUserId AND
​ ​ A.QuizId = @IQuizId AND A.isActive=1​ ​
​ END

​ IF @IMode= 'INS'
​ BEGIN
​ ​ IF exists(SELECT QuestionId FROM QuestionSet WHERE QuizId=@IQuizId
AND questionDescription=@IquestionDescription)
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Question already exists in this Quiz, please choose
a different question!'
​ ​ ​ RETURN
​ ​ END
​ ​ SET @MyCnt=0
​ ​ SELECT @MyCnt=COUNT(QuestionId) FROM QuestionSet WHERE
QuizId=@IQuizId

178
​ ​ IF @MyCnt >=10
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Max 10 Question Allowed in a Quiz!'
​ ​ ​ RETURN
​ ​ END
​ ​
​ ​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ INSERT INTO QuestionSet(QuizId, questionDescription, questionHint,
optionA, optionB, optionC, optionD, optionE, Answer, isActive, IPAddress, TransDate,
UserId)
​ ​ ​ ​ ​ VALUES(@IQuizId,@IquestionDescription,
@IquestionHint, @IoptionA,@IoptionB, @IoptionC, @IoptionD, @IoptionE, @IAnswer,
@IisActive,
​ ​ ​ ​ ​ ​ @IIPaddress, GETDATE(), @IUserId)
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ ​ END TRY

​ ​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ RETURN ERROR_MESSAGE()
​ ​ END CATCH
​ END
​ IF @IMode= 'UPD'
​ BEGIN
​ ​ IF exists(SELECT QuestionId FROM QuestionSet WHERE QuizId=@IQuizId
AND QuestionId<>@IQuestionId AND questionDescription=@IquestionDescription)
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Question already exists in this Quiz, please choose
a different name!'
​ ​ ​ RETURN
​ ​ END

​ ​ IF EXISTS(SELECT QuizId FROM StudentPerformanceDetails WHERE


QuizId=@IQuizId)
​ ​ BEGIN
​ ​ ​ SET @StrResult='You cannot modify the Question because it is
already in process!'
​ ​ ​ RETURN
​ ​ END
​ ​ ​
​ ​ BEGIN TRY
​ ​ ​ BEGIN TRANSACTION
​ ​ ​ UPDATE QuestionSet SET
​ ​ ​ questionDescription=@IquestionDescription,
​ ​ ​ questionHint=@IquestionHint,
​ ​ ​ optionA=@IoptionA,

179
​ ​ ​ optionB=@IoptionB,
​ ​ ​ optionC=@IoptionC,
​ ​ ​ optionD=@IoptionD,
​ ​ ​ optionE=@IoptionE,
​ ​ ​ Answer=@IAnswer,
​ ​ ​ isActive=@IisActive
​ ​ ​ WHERE QuizId=@IQuizId AND QuestionId=@IQuestionId
​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ ​ COMMIT TRANSACTION
​ ​ END TRY
​ ​ BEGIN CATCH
​ ​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ ​ END CATCH
​ END

​ IF @IMode='DAC'
​ BEGIN
​ ​ IF EXISTS(SELECT QuizId FROM StudentPerformanceDetails WHERE
QuizId=@IQuizId)
​ ​ BEGIN
​ ​ ​ SET @StrResult='You cannot delete the Question because it is
already in process!'
​ ​ ​ RETURN
​ ​ END
​ ​ BEGIN TRY
​ ​ ​ BEGIN TRANSACTION
​ ​ ​ UPDATE QuestionSet SET isActive=0 WHERE QuizId=@IQuizId AND
QuestionId=@IQuestionId AND isActive=1
​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ ​
​ ​ ​ COMMIT TRANSACTION
​ ​ END TRY
​ ​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ RETURN ERROR_MESSAGE()
​ ​ END CATCH
​ END
END

Stored Procedure: QuizInfo

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[QuizInfo] Script Date: 11/30/2024 8:20:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

180
GO
ALTER PROC [dbo].[QuizInfo]
(
@Mode​ ​ ​ CHAR(3),
@IQuizId​ ​ INT​ =​ NULL,
@IQuizName​ ​ VARCHAR(50)​ =​ NULL,
@ITeacherId​ ​ INT​ =​ NULL,
@ITopicId​ ​ INT​ =​ NULL,
@ILevelId​ ​ INT​ =​ NULL,
@ITotalQuestions​ ​ INT​ =​ NULL,
@IisActive​ ​ BIT​ =​ NULL,
@IIPaddress​ ​ VARCHAR(15)​ =​ NULL,
@IUserId​ ​ INT​ ​ ​ =​ NULL,
@StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
​ SET NOCOUNT ON
​ DECLARE @MyMaxMarks AS INT=0
​ DECLARE @MyMinMarks AS INT=0
​ DECLARE @MyDuration AS INT=0

​ IF @Mode='DD1' --List of topics
​ BEGIN
​ ​ SELECT TopicId, TopicName FROM TopicDetails WHERE isActive=1
​ END

​ IF @Mode='DD2' --List of Difficulty levels


​ BEGIN
​ ​ SELECT LevelId, LevelName FROM DifficultyLevel WHERE isActive=1
​ END
​ IF @Mode='DD3' --Quiz List
​ BEGIN
​ ​ SELECT A.QuizId, A.QuizName+' : By '+B.FirstName +' ,
'+CAST(A.TotalQuestions AS VARCHAR) +' Question, '+CAST(A.MaxMarks AS
VARCHAR)+' Marks &'+CAST(A.Duration AS VARCHAR)+' Sec./Que. ' AS QuizName
​ ​ FROM Quiz A
​ ​ INNER JOIN Teacher B ON B.TeacherId=A.TeacherId
​ ​ WHERE A.isActive=1 AND A.TopicId=@ITopicId
​ END
​ --IF @Mode='DD3' --Quiz List
​ --BEGIN
​ --​ SELECT A.QuizId, A.QuizName+' : Created By '+B.FirstName +' ,Total No
Questions '+CAST(A.TotalQuestions AS VARCHAR) +' ,Max Marks '+CAST(A.MaxMarks AS
VARCHAR)+' ,Duration '+CAST(A.Duration AS VARCHAR)+' Seconds/Question ' AS
QuizName
​ --​ FROM Quiz A
​ --​ INNER JOIN Teacher B ON B.TeacherId=A.TeacherId
​ --​ WHERE A.isActive=1 AND A.TopicId=@ITopicId

181
​ --END
​ IF @Mode='DG1'
​ BEGIN
​ ​ SELECT A.QuizId , A.QuizName, B.FirstName + ' '+ B.Surname AS
TeacherName, C.TopicName, D.LevelName, A.TotalQuestions, A.MaxMarks, A.MinMarks,
A.Duration, A.isActive,
​ ​ A.IPAddress, A.TransDate , A.UserId FROM Quiz A
​ ​ INNER JOIN Teacher B ON B.TeacherId= A.TeacherId
​ ​ INNER JOIN TopicDetails C​ ON​ C.TopicId= A.TopicId
​ ​ INNER JOIN DifficultyLevel​ D ON D.LevelId= A.LevelId

​ END

​ IF @Mode= 'INS'
​ BEGIN
​ ​ IF exists(SELECT QuizId FROM Quiz WHERE QuizName=@IQuizName)
​ ​ BEGIN
​ ​ ​ SET @StrResult= 'Quiz Name already exists, please choose a
different name!'
​ ​ ​ RETURN
​ ​ END
​ ​ IF @ILevelId=1
​ ​ BEGIN
​ ​ ​ SET @MyMaxMarks=@ITotalQuestions*1
​ ​ ​ SET @MyMinMarks=@ITotalQuestions*0.8
​ ​ ​ SET @MyDuration=@ITotalQuestions*0.5
​ ​ END
​ ​ IF @ILevelId=2
​ ​ BEGIN
​ ​ ​ SET @MyMaxMarks=@ITotalQuestions*2
​ ​ ​ SET @MyMinMarks=@ITotalQuestions*0.8
​ ​ ​ SET @MyDuration=@ITotalQuestions*1.5
​ ​ END
​ ​ IF @ILevelId=3
​ ​ BEGIN
​ ​ ​ SET @MyMaxMarks=@ITotalQuestions*3
​ ​ ​ SET @MyMinMarks=@ITotalQuestions*0.8
​ ​ ​ SET @MyDuration=@ITotalQuestions*3
​ ​ END
​ ​
​ ​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ INSERT INTO Quiz(QuizName, TeacherId, TopicId, LevelId, TotalQuestions,
MaxMarks, MinMarks, Duration, isActive,
​ ​ ​ ​ ​ ​ IPAddress, TransDate, UserId)
​ ​ ​ ​ ​ VALUES(@IQuizName, @ITeacherId, @ITopicId,
@ILevelId, @ITotalQuestions, @MyMaxMarks, @MyMinMarks, @MyDuration, @IisActive,
​ ​ ​ ​ ​ ​ @IIPaddress, GETDATE(), @IUserId)

182
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ ​ END TRY

​ ​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ RETURN ERROR_MESSAGE()
​ ​ END CATCH
​ END
​ IF @Mode= 'UPD'
​ BEGIN
​ ​ IF Exists(SELECT QuizId FROM Quiz WHERE QuizId!=@IQuizId and
QuizName=@IQuizName)
​ ​ BEGIN
​ ​ ​ SET @StrResult='Quiz already exists with this name!'
​ ​ ​ RETURN
​ ​ END

​ ​ IF EXISTS(SELECT QuizId FROM StudentPerformanceDetails WHERE


QuizId=@IQuizId)
​ ​ BEGIN
​ ​ ​ SET @StrResult='You cannot modify the quiz because it is already in
process!'
​ ​ ​ RETURN
​ ​ END
​ ​ ​ IF @ILevelId=1
​ ​ BEGIN
​ ​ ​ SET @MyMaxMarks=@ITotalQuestions*1
​ ​ ​ SET @MyMinMarks=@ITotalQuestions*0.8
​ ​ ​ SET @MyDuration=@ITotalQuestions*0.5
​ ​ END
​ ​ IF @ILevelId=2
​ ​ BEGIN
​ ​ ​ SET @MyMaxMarks=@ITotalQuestions*2
​ ​ ​ SET @MyMinMarks=@ITotalQuestions*0.8
​ ​ ​ SET @MyDuration=@ITotalQuestions*1.5
​ ​ END
​ ​ IF @ILevelId=3
​ ​ BEGIN
​ ​ ​ SET @MyMaxMarks=@ITotalQuestions*3
​ ​ ​ SET @MyMinMarks=@ITotalQuestions*0.8
​ ​ ​ SET @MyDuration=@ITotalQuestions*3
​ ​ END
​ ​ BEGIN TRY
​ ​ ​ BEGIN TRANSACTION
​ ​ ​ UPDATE Quiz SET
​ ​ ​ QuizName=@IQuizName,
​ ​ ​ TopicId=@ITopicId,

183
​ ​ ​ LevelId=@ILevelId,
​ ​ ​ TotalQuestions=@ITotalQuestions,
​ ​ ​ MaxMarks=@MyMaxMarks,
​ ​ ​ MinMarks=@MyMinMarks,
​ ​ ​ Duration=@MyDuration,
​ ​ ​ isActive=@IisActive
​ ​ ​ WHERE QuizId=@IQuizId
​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ ​ COMMIT TRANSACTION
​ ​ END TRY
​ ​ BEGIN CATCH
​ ​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ ​ END CATCH
​ END

​ IF @Mode='DAC'
​ BEGIN
​ ​ IF EXISTS(SELECT QuizId FROM StudentPerformanceDetails WHERE
QuizId=@IQuizId)
​ ​ BEGIN
​ ​ ​ SET @StrResult='You cannot delete the quiz because it is already in
process!'
​ ​ ​ RETURN
​ ​ END
​ ​ BEGIN TRY
​ ​ ​ BEGIN TRANSACTION
​ ​ ​ UPDATE Quiz SET isActive=0 WHERE QuizId=@IQuizId and
isActive=1
​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ ​ COMMIT TRANSACTION
​ ​ END TRY
​ ​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ RETURN ERROR_MESSAGE()
​ ​ END CATCH
​ END
END

Stored Procedure: SignUpInfo

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[SignUpInfo] Script Date: 11/30/2024 8:20:56 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

184
GO
ALTER proc [dbo].[SignUpInfo]
(​
​ @IMode CHAR(3)​ ​ =​ NULL,
​ @IUserTypeId​INT​ ​ ​ =​ NULL,
​ @ISurname​ ​ VARCHAR(50)​ =​ NULL,
​ @IFirstName​ ​ VARCHAR(50)​ =​ NULL,
​ @IGenderId​ ​ VARCHAR(10) =​ NULL,
​ @IMobileNo​ ​ VARCHAR(10)​ =​ NULL,
​ @IEmailId​ ​ VARCHAR(50)​ =​ NULL,
​ @IPwd​​ ​ VARCHAR(50)​ =​ NULL,
​ @IIPAddress​ ​ VARCHAR(15)​ =​ NULL,
​ @StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
DECLARE @MyCnt INT= 0

if (@IMode= 'REG')--New User Registeration


BEGIN
IF @IUserTypeId=1--Student
​ BEGIN
​ ​ if exists(select StudentId from Student where MobileNo= @IMobileNo and
emailId= @IEmailId)
​ ​ BEGIN
​ ​ ​ SET @StrResult='Student already exists with this mobile number or
email.'
​ ​ ​ RETURN
​ ​ END​ ​
​ END
​ IF @IUserTypeId=3--Teacher
​ BEGIN
​ ​ if exists(select TeacherId from Teacher where MobileNo= @IMobileNo and
emailId= @IEmailId)
​ ​ BEGIN
​ ​ ​ SET @StrResult='Teacher already exists with this mobile number or
email.'
​ ​ ​ RETURN
​ ​ END
​ END

​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​
​ ​ ​ INSERT INTO UserDetails(UserTypeId, LoginId, Pwd,
ChangePasswordDate, FirstName, TransDate, Deactive, LoginDate, IPAddress, CNT,
DACTIVE_TIME)
​ ​ ​ ​ VALUES(@IUserTypeId, @IEmailId, @IPwd, NULL,
@IFirstName, GETDATE(), 0, NULL, @IIPAddress, 0, NULL)

185
​ ​ ​ DECLARE @MYUserId AS BIGINT
​ ​ ​ SET @MYUserId=@@IDENTITY

​ ​ ​ IF @IUserTypeId=1--Student
​ ​ ​ BEGIN
​ ​ ​ ​ INSERT INTO Student(Surname, firstName, Age, GenderId,
GradeId, EmailId, MobileNo, totalTrophies, totalCertificates, isActive, IPAddress, TransDate,
UserId)
​ ​ ​ ​ ​ ​ values(@ISurname, @IFirstName, 0,
@IGenderId, 0, @IEmailId, @IMobileNo, 0, 0, 1, @IIPAddress, GETDATE(), @MYUserId)
​ ​ ​ END
​ ​ ​ IF @IUserTypeId=3--Teacher
​ ​ ​ BEGIN
​ ​ ​ ​ INSERT INTO Teacher(Surname, firstName, Age, GenderId,
EmailId, MobileNo, isActive, IPAddress, TransDate, UserId)
​ ​ ​ ​ ​ ​ ​ values(@ISurname, @IFirstName, 0,
@IGenderId, @IEmailId, @IMobileNo, 1, @IIPAddress, getDate(), @MYUserId)
​ ​ ​ END
​ ​ ​ SET @StrResult = 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END

END

Stored Procedure: StudentInfo

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[StudentInfo] Script Date: 11/30/2024 8:21:18 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[StudentInfo]
(​
​ @Mode CHAR(3)​ ​ ​ ​ =​ NULL,
​ @IStudentId​ ​ INT​ ​ ​ =​ NULL,
​ @ISurname​ ​ VARCHAR(50)​ =​ NULL,
​ @IfirstName​ ​ VARCHAR(50)​ =​ NULL,
​ @IPwd​​ ​ VARCHAR(50)​ =​ NULL,
​ @IAge​​ ​ INT​ =​ NULL,

186
​ @IGenderId​ ​ INT = NULL,
​ @IGradeId​ ​ ​ INT​ ​ ​ =​ NULL,
​ @IEmailId​ ​ VARCHAR(50)​ =​ NULL,
​ @IMobileNo​ ​ VARCHAR(10)​ =​ NULL,
​ @ITotalTrophies​ ​ INT​ =​ NULL,
​ @ItotalCertificates​ ​ INT​ =​ NULL,
​ @IisActive​ ​ BIT​ ​ ​ =​ NULL,
​ @IIPAddress​ ​ VARCHAR(15)​ =​ NULL,
​ @IUserId​ ​ INT​ =​ NULL,
​ @StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
DECLARE @MyCnt INT= 0

IF @Mode='DD1'--Grade
​ BEGIN
​ SELECT gradeid,grade,isActive FROM GradeMaster WHERE IsActive=1 ORDER
BY GradeId
​ END
IF @Mode='DD2'--Gender
​ BEGIN
​ ​ SELECT GenderId,Gender,isActive FROM GenderMaster WHERE IsActive=1
ORDER BY GenderId
​ END
IF @Mode='DD3'--Student List
​ BEGIN
​ ​ SELECT A.UserId AS studentId,A.FirstName+' '+A.Surname+'
('+B.Gender+')'+' Grade :'+CAST(ISNULL(A.GradeId,-1) AS VARCHAR)+' ,Email
Id:'+A.EmailId+' ,Mobile No:'+A.MobileNo AS studentName
​ ​ FROM Student​ ​ ​ ​ A
​ ​ INNER JOIN GenderMaster​ ​ B​ ON B.GenderId = A.GenderId
​ ​ WHERE A.IsActive=1 ORDER BY StudentId
​ END
IF (@Mode= 'GET')--BIND Student Details
​ BEGIN
​ select surname, firstName,A.GenderId, B.gender, emailID,mobileNo,ISNULL(age,0)
AS age,ISNULL(A.gradeId,0) AS gradeId, C.grade,userId
​ FROM Student​ ​ ​ ​ A
​ INNER JOIN GenderMaster​ ​ B​ ON B.GenderId =A.GenderId
​ LEFT OUTER JOIN GradeMaster​ C​ ON C.GradeId =A.GradeId​
​ WHERE UserId=@IUserId
END
IF (@Mode= 'DG1')--BIND Students Details
BEGIN
​ select studentId, surname, firstName,A.gradeId, B.grade, emailID, age,A.GenderId,
C.gender, mobileNo, totalTrophies, totalCertificates, ipAddress, transDate,A.isActive,userId
​ from Student​ ​ ​ A
​ INNER JOIN GradeMaster​ B​ ON B.GradeId =A.GradeId

187
​ INNER JOIN GenderMaster C​ ON C.GenderId =A.GenderId
​ order by StudentId desc
END
IF @Mode='ACH'--Achievements
​ BEGIN
​ ​ SELECT TotalTrophies,TotalCertificates from Student WHERE UserId
=@IUserId
​ END

if (@Mode= 'UPD')
BEGIN
​ if exists(select StudentId from Student where StudentId!=@IStudentId and MobileNo
= @IMobileNo)
​ BEGIN
​ ​ SET @StrResult='Student already exists with this mobile number.'
​ ​ RETURN
​ END
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE Student SET
​ ​ ​ ​ ​ ​ Surname= @ISurname,
​ ​ ​ ​ ​ ​ firstName=@IfirstName,
​ ​ ​ ​ ​ ​ GenderId=@IGenderId,
​ ​ ​ ​ ​ ​ MobileNo= @IMobileNo,
​ ​ ​ ​ ​ ​ Age​ ​ = @IAge
​ ​ ​ ​ ​ ​ where UserId=@IUserId
​ ​ ​ ​ ​ ​ SET @StrResult='SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END

if (@Mode= 'DAC')
BEGIN
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE Student SET
​ ​ ​ ​ ​ ​ isActive=0
​ ​ ​ ​ ​ ​ where StudentId=@IStudentId
​ ​ ​ ​ ​ ​ SET @StrResult='SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION

188
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END
END

Stored Procedure: TeacherInfo

USE [FBG]
GO
/****** Object: StoredProcedure [dbo].[TeacherInfo] Script Date: 11/30/2024 8:21:29 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[TeacherInfo]
(​
​ @Mode CHAR(3)​ ​ =​ NULL,
​ @ITeacherId​ ​ INT​ ​ ​ =​ NULL,
​ @ISurname​ ​ VARCHAR(50)​ =​ NULL,
​ @IFirstName​ ​ VARCHAR(50)​ =​ NULL,
​ @IPwd​​ ​ VARCHAR(50)​ =​ NULL,
​ @IAge​​ ​ INT​ =​ NULL,
​ @IGenderId​ ​ VARCHAR(10) = NULL,
​ @IEmailId​ ​ VARCHAR(50)​ =​ NULL,
​ @IMobileNo​ ​ VARCHAR(10)​ =​ NULL,
​ @IisActive​ ​ BIT​ ​ ​ =​ NULL,
​ @IIPAddress​ ​ VARCHAR(15)​ =​ NULL,
​ @IUserId​ ​ INT​ =​ NULL,
​ @StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
DECLARE @MyCnt INT= 0
IF (@Mode= 'DG1') --Bind Teachers Details
BEGIN
​ select A.TeacherId, A.Surname, A.firstName,A.GenderId ,B.Gender, A.Age,
A.emailID, A.MobileNo, A.isActive, A.IPAddress, A.TransDate, A.UserId
​ from Teacher A
​ INNER JOIN GenderMaster B​ ON B.GenderId =A.GenderId
​ order by TeacherId desc
END
IF (@Mode= 'GET')--Bind Teacher Details
​ BEGIN
​ select surname, firstName,A.GenderId, B.gender, emailID, mobileNo, age,userId
​ from Teacher​ ​ ​ A
​ INNER JOIN GenderMaster B​ ON B.GenderId =A.GenderId
​ where UserId=@IUserId
END

189
​ if (@Mode= 'UPD')--Update Teacher Details
BEGIN
​ if exists(select TeacherId from Teacher where TeacherId!=@ITeacherId and
MobileNo= @IMobileNo or emailId= @IEmailId)
​ BEGIN
​ ​ SET @StrResult='Teacher already exists with this mobile number or email.'
​ ​ RETURN
​ END
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE Teacher SET
​ ​ ​ ​ ​ ​ Surname= @ISurname,
​ ​ ​ ​ ​ ​ firstName=@IfirstName,
​ ​ ​ ​ ​ ​ GenderId=@IGenderId,
​ ​ ​ ​ ​ ​ MobileNo= @IMobileNo,
​ ​ ​ ​ ​ ​ Age​ ​ = @IAge
​ ​ ​ ​ ​ ​ where UserId=@IUserId
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END

if (@Mode= 'DAC')--DeActive Teacher Details


BEGIN
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE Teacher SET
​ ​ ​ ​ ​ ​ isActive=0
​ ​ ​ ​ ​ ​ where TeacherId=@ITeacherId
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END
END

Stored Procedure: TopicInfo

USE [FBG]
GO

190
/****** Object: StoredProcedure [dbo].[TopicInfo] Script Date: 11/30/2024 8:21:48 PM
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[TopicInfo]
(​
​ @Mode CHAR(3)​ ​ =​ NULL,
​ @ITopicId​ ​ INT​ ​ ​ =​ NULL,
​ @ITopicName​​ VARCHAR(20)​ =​ NULL,
​ @IisActive​ ​ INT​ =​ NULL,
​ @IUserId​ ​ INT​ =​ NULL,
​ @StrResult​ ​ VARCHAR(150)=​ 'ERROR' OUTPUT
)
AS BEGIN
DECLARE @MyCnt INT= 0

IF @Mode='DD1' --List of topics


BEGIN
​ SELECT TopicId, TopicName FROM TopicDetails WHERE isActive=1
END
IF (@Mode= 'STS')---Individual Student Topic wise Status from Student
BEGIN
​ IF EXISTS(SELECT StudentId FROM StudentPerformanceDetails WHERE UserID =
@IUserId)
​ BEGIN
​ ​ select A.TopicName,B.QuizName,C.FirstName+' '+C.Surname AS
TeacherName,B.TotalQuestions,B.MaxMarks,B.MinMarks,(B.Duration*B.TotalQuestions)/60
AS Duration,ISNULL(D.TransDate,'1900-01-01') AS
PlayDate,ISNULL(D.StartTime,'00:00:00') AS StartTime,ISNULL(D.EndTime,'00:00:00') AS
EndTime,D.Accuracy,CASE WHEN D.Result= 'F' THEN 'Draft' WHEN D.Result ='P' THEN
'Done' ELSE 'Pending' END AS Result
​ ​ from TopicDetails​ ​ ​ ​ ​ ​ ​ A
​ ​ INNER JOIN Quiz​ ​ ​ ​ ​ ​ ​ ​ B
ON B.TopicId​ ​ =​ A.TopicId
​ ​ INNER JOIN Teacher​​ ​ ​ ​ ​ ​ C ON
C.TeacherId​ =​ B.TeacherId
​ ​ LEFT OUTER JOIN​ StudentPerformanceDetails​ D ON D.QuizId​
​ =​ B.QuizId
​ ​ WHERE D.UserID = @IUserId
​ ​ UNION
​ ​ select A.TopicName,B.QuizName,C.FirstName+' '+C.Surname AS
TeacherName,B.TotalQuestions,B.MaxMarks,B.MinMarks,(B.Duration*B.TotalQuestions)/60
AS Duration,CAST('1900-01-01' AS DATE) AS PlayDate,CAST('00:00:00'AS DATE) AS
StartTime,CAST('00:00:00'AS DATE) AS EndTime,NULL AS Score,'Pending' AS Result
​ ​ from TopicDetails​ ​ ​ ​ ​ ​ ​ A

191
​ ​ INNER JOIN Quiz​ ​ ​ ​ ​ ​ ​ ​ B
ON B.TopicId​ ​ =​ A.TopicId
​ ​ INNER JOIN Teacher​​ ​ ​ ​ ​ ​ C ON
C.TeacherId​ =​ B.TeacherId
​ WHERE B.QuizId NOT IN (SELECT QuizId FROM StudentPerformanceDetails
WHERE UserID = @IUserId)​​

​ END
​ ELSE
​ BEGIN
​ ​ select A.TopicName,B.QuizName,C.FirstName+' '+C.Surname AS
TeacherName,B.TotalQuestions,B.MaxMarks,B.MinMarks,(B.Duration*B.TotalQuestions)/60
AS Duration,CAST('1900-01-01' AS DATE) AS PlayDate,CAST('00:00:00'AS DATE) AS
StartTime,CAST('00:00:00'AS DATE) AS EndTime,NULL AS Score,'Pending' AS Result
​ ​ from TopicDetails​ ​ ​ ​ ​ ​ ​ A
​ ​ INNER JOIN Quiz​ ​ ​ ​ ​ ​ ​ ​ B
ON B.TopicId​ ​ =​ A.TopicId
​ ​ INNER JOIN Teacher​​ ​ ​ ​ ​ ​ C ON
C.TeacherId​ =​ B.TeacherId
​ ​ --LEFT OUTER JOIN​ StudentPerformanceDetails​ D ON D.QuizId​
​ =​ B.QuizId
​ ​ order by A.TopicId asc
​ END
END

IF (@Mode= 'SPS')------Student performance Status which is coverd from Student/Teacher


BEGIN
​ select A.TopicName,B.QuizName,C.FirstName+' '+C.Surname AS
TeacherName,B.TotalQuestions,B.MaxMarks,B.MinMarks,(B.Duration*B.TotalQuestions)/60
AS Duration,ISNULL(D.TransDate,'1900-01-01') AS
PlayDate,ISNULL(D.StartTime,'00:00:00') AS StartTime,ISNULL(D.EndTime,'00:00:00') AS
EndTime,D.Accuracy,CASE WHEN D.Result= 'F' THEN 'Draft' WHEN D.Result ='P' THEN
'Done' ELSE 'N/A' END AS Result
​ ​ from TopicDetails​ ​ ​ ​ ​ ​ ​ A
​ ​ INNER JOIN Quiz​ ​ ​ ​ ​ ​ ​ ​ B
ON B.TopicId​ ​ =​ A.TopicId
​ ​ INNER JOIN Teacher​​ ​ ​ ​ ​ ​ C ON
C.TeacherId​ =​ B.TeacherId
​ ​ INNER JOIN​ StudentPerformanceDetails​ D ON D.QuizId​ ​ =
​ B.QuizId
​ ​ WHERE D.UserID = @IUserId
​ ​ ORDER BY PId DESC
END

IF (@Mode= 'DG1')
BEGIN
​ select TopicId, TopicName, isActive, UserId from TopicDetails order by TopicId desc
END

192
if (@Mode= 'INS')
BEGIN
​ if exists(select TopicId from TopicDetails where TopicName= @ITopicName)
​ BEGIN
​ ​ SET @StrResult='Topic already exists.'
​ ​ RETURN
​ END
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ INSERT INTO TopicDetails(TopicName, isActive, TransDate, UserId)
​ ​ ​ ​ ​ ​ values(@ITopicName, 1, getDate(), @IUserId)
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END
​ if (@Mode= 'UPD')
BEGIN
​ if exists(select TopicId from TopicDetails where TopicId!=@ITopicId and TopicName=
@ITopicName)
​ BEGIN
​ ​ SET @StrResult='Topic name already exists.'
​ ​ RETURN
​ END
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE TopicDetails SET
​ ​ ​ ​ ​ ​ TopicName=@ITopicName,
​ ​ ​ ​ ​ ​ isActive=@IisActive
​ ​ ​ ​ ​ ​ where TopicId=@ITopicId
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END

if (@Mode= 'DAC')
BEGIN
​ BEGIN TRY
​ ​ BEGIN TRANSACTION
​ ​ ​ ​ ​ ​ UPDATE TopicDetails SET
​ ​ ​ ​ ​ ​ isActive=0

193
​ ​ ​ ​ ​ ​ where TopicId=@ITopicId
​ ​ ​ ​ ​ ​ SET @StrResult= 'SUCCESS'
​ ​ COMMIT TRANSACTION
​ END TRY
​ BEGIN CATCH
​ ​ ROLLBACK TRANSACTION
​ ​ ​ RETURN ERROR_MESSAGE()
​ END CATCH
END
END

194

You might also like