D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
cas
/
application
/
controllers
/
student
/
Filename :
TasksAndQuizzes.php
back
Copy
<?php /** * Controller For Handling All Requests Related To Quizzes & Assignments * * @author Softpro India Pvt. Ltd. */ defined('BASEPATH') OR exit('No direct script access allowed'); class TasksAndQuizzes extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('admin/TaskAndQuizManagement'); } public function index() { if ($this->sessionvalidator->isStudentLoggedIn()) { $modelPapers = $this->TaskAndQuizManagement->getAllottedModelPapersByStudent($this->session->userdata("studentData")["stu_id"])->result(); $myModelPapers = array(); for ($i = 0; $i < sizeof($modelPapers); $i++) { $result = "Not Available"; $attemptedCount = sizeof($this->TaskAndQuizManagement->getModelPaperAttemptByStudent($this->session->userdata("studentData")["stu_id"], $modelPapers[$i]->mepm_id)->result()); if ($attemptedCount) { $responseData = $this->TaskAndQuizManagement->getModelPaperAttemptResponseByStudent($this->session->userdata("studentData")["stu_id"], $modelPapers[$i]->mepm_id)->result(); if (sizeof($responseData)) { $mMarks = 0.0; $marksObtained = 0.0; for ($j = 0; $j < sizeof($responseData); $j++) { $correctResponse = $responseData[$j]->meprm_correct_resp; $markedResponse = $responseData[$j]->meprm_obj_resp; if ($markedResponse == $correctResponse) { $marksObtained += $responseData[$j]->qb_marks; } else { if ($responseData[$j]->qb_negative_marks != NULL || $responseData[$j]->qb_negative_marks != "") { $marksObtained -= $responseData[$j]->qb_negative_marks; } } $mMarks += $responseData[$j]->qb_marks; } $result = $marksObtained . "/" . $mMarks; } else { $result = "Not Available"; } } array_push($myModelPapers, array( 'mepm_id' => $modelPapers[$i]->mepm_id, 'mepm_title' => stripslashes($modelPapers[$i]->mepm_title), 'sm_name' => stripslashes($modelPapers[$i]->sm_name), 'mepm_type' => ($modelPapers[$i]->mepm_type == "O") ? "Objective" : (($modelPapers[$i]->mepm_type == "S") ? "Subjective" : "Miscellaneous"), 'mepm_added_by' => $modelPapers[$i]->addedByAdmin, 'mepsa_start_date' => $modelPapers[$i]->mepsch_start_date, 'mepsa_end_date' => $modelPapers[$i]->mepsch_end_date, 'mepsa_is_result_to_show' => $modelPapers[$i]->mepsch_is_result_to_show, 'mepsa_is_detailed_result_to_show' => $modelPapers[$i]->mepsch_is_detailed_result_to_show, 'mepsa_attempt_allowed' => ($modelPapers[$i]->mepsch_allowed_attempts == 0) ? 1 : ($modelPapers[$i]->mepsch_allowed_attempts - $attemptedCount), 'mepsa_normal_result' => $result, 'mepsa_detailed_result' => '' )); } $viewData['myModelPapers'] = $myModelPapers; $this->load->view('student/assessment/modelPapers', $viewData); } else { redirect("student/"); } } public function attemptModelPaper($mepm_id) { if ($this->sessionvalidator->isStudentLoggedIn()) { if (trim($mepm_id) != "") { $modelPaperInfo = $this->TaskAndQuizManagement->getModelExamPaperInfoBy($mepm_id)->result(); $modelPaperAllottmentInfo = $this->TaskAndQuizManagement->getAllottedModelPaperInfoBy($mepm_id)->result()[0]; if (sizeof($modelPaperInfo)) { $thisModelPaper = $modelPaperInfo[0]; $gen_questions = $this->TaskAndQuizManagement->getModelExamPaperGeneralQuestionsBy($mepm_id)->result(); $group_questions = $this->TaskAndQuizManagement->getModelExamPaperGroupQuestionsBy($mepm_id)->result(); $attemptedCount = sizeof($this->TaskAndQuizManagement->getModelPaperAttemptByStudent($this->session->userdata("studentData")["stu_id"], $thisModelPaper->mepm_id)->result()); if (($modelPaperAllottmentInfo->mepsch_allowed_attempts == 0) || ($modelPaperAllottmentInfo->mepsch_allowed_attempts - $attemptedCount)) { if (!($attemptedCount)) { $response_array = array(); for ($i = 0; $i < sizeof($gen_questions); $i++) { array_push($response_array, array( 'mepqm_id' => $gen_questions[$i]->mepqm_id, 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'qb_id' => $gen_questions[$i]->qb_id, 'mepm_id' => $mepm_id, 'meprm_correct_resp' => $gen_questions[$i]->qb_correct_opt, 'mepsch_id' => $modelPaperAllottmentInfo->mepsch_id, 'meprm_first_attempted' => date("Y-m-d H:i:s"), 'meprm_updated_on' => date("Y-m-d H:i:s") )); } for ($i = 0; $i < sizeof($group_questions); $i++) { array_push($response_array, array( 'mepqm_id' => $group_questions[$i]->mepqm_id, 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'qb_id' => $group_questions[$i]->qb_id, 'mepm_id' => $mepm_id, 'meprm_correct_resp' => $group_questions[$i]->qb_correct_opt, 'mepsch_id' => $modelPaperAllottmentInfo->mepsch_id, 'meprm_first_attempted' => date("Y-m-d H:i:s"), 'meprm_updated_on' => date("Y-m-d H:i:s") )); } $attempt_array = array( 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'mepm_id' => $mepm_id, 'mepsch_id' => $modelPaperAllottmentInfo->mepsch_id, 'mepsat_attempted_on' => date("Y-m-d H:i:s") ); $this->db->trans_start(); if ($this->TaskAndQuizManagement->createNewStudentAttempt($attempt_array)) { if ($this->TaskAndQuizManagement->createNewStudentResponse($response_array)) { $this->db->trans_complete(); $viewData['genQuestions'] = $gen_questions; $viewData['groupQuestions'] = $group_questions; $viewData['modelPaperInfo'] = $thisModelPaper; $this->load->view('student/assessment/attemptModelPaper', $viewData); } else { $this->session->set_flashdata('errorMessage', 'Sorry! Some Error Occured While Making Attempt To View Model Paper. Please Try Later.'); redirect("student/TasksAndQuizzes/"); } } else { $this->session->set_flashdata('errorMessage', 'Sorry! Some Error Occured While Making Attempt To View Model Paper. Please Try Later.'); redirect("student/TasksAndQuizzes/"); } } else { $attempt_array = array( 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'mepm_id' => $mepm_id, 'mepsch_id' => $modelPaperAllottmentInfo->mepsch_id, 'mepsat_attempted_on' => date("Y-m-d H:i:s") ); if ($this->TaskAndQuizManagement->createNewStudentAttempt($attempt_array)) { $viewData['genQuestions'] = $gen_questions; $viewData['groupQuestions'] = $group_questions; $viewData['modelPaperInfo'] = $thisModelPaper; $this->load->view('student/assessment/attemptModelPaper', $viewData); } else { $this->session->set_flashdata('errorMessage', 'Sorry! Some Error Occured While Making Attempt To View Model Paper. Please Try Later.'); redirect("student/TasksAndQuizzes/"); } } } else { redirect("student/TasksAndQuizzes/"); } } else { $this->session->set_flashdata('errorMessage', 'Sorry! Model Paper Revoked Or This Model Paper Does Not Exits Any More.'); redirect("student/TasksAndQuizzes/"); } } else { redirect("student/"); } } } public function saveModelPaperAttempt() { if ($this->sessionvalidator->isStudentLoggedIn()) { $questionIds = $this->input->post("questionIds"); $mepmType = $this->input->post("mepm_type"); if ($mepmType == "O") { $this->db->trans_start(); for ($i = 0; $i < sizeof($questionIds); $i++) { $responseUpdateArray = array( 'meprm_obj_resp' => $this->input->post("question" . $questionIds[$i]), 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'qb_id' => $questionIds[$i], 'mepm_id' => trim($this->input->post("mepm_id")), 'meprm_updated_on' => date("Y-m-d H:i:s") ); $this->TaskAndQuizManagement->updateNewStudentResponse($responseUpdateArray); } if ($i == sizeof($questionIds)) { $this->session->set_flashdata('successMessage', 'Model Paper Submitted Successfully.'); redirect("student/TasksAndQuizzes/"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Model Paper. Try Later.'); redirect("student/TasksAndQuizzes/"); } } else { $this->db->trans_start(); for ($i = 0; $i < sizeof($questionIds); $i++) { $inputFileName = "file" . $questionIds[$i]; if (!empty($_FILES[$inputFileName]['name'])) { $responseFileWithPath = ""; $configResponseFile['upload_path'] = './assets/admin/uploads/questionBank/studentResponse/'; $configResponseFile['allowed_types'] = 'jpeg|jpg|png'; $configResponseFile['max_size'] = '500'; $configResponseFile['file_ext_tolower'] = TRUE; $configResponseFile['encrypt_name'] = TRUE; $this->load->library('upload', $configResponseFile); if (!$this->upload->do_upload($inputFileName)) { $this->session->set_flashdata('errorMessage', "The Response Image File Can Not Be Uploaded As It Do Not Match With Response Image Criteria. File Size 500 KB Max. & Allowed Extension: Only *.png,*.jpg,*.jpeg."); $this->attemptModelPaper(trim($this->input->post("mepm_id"))); } else { $responseFileWithPath = "/assets/admin/uploads/questionBank/studentResponse/" . $this->upload->data()['file_name']; $responseUpdateArray = array( 'meprm_sub_resp' => addslashes(trim($this->input->post("question" . $questionIds[$i]))), 'meprm_sub_file' => $responseFileWithPath, 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'qb_id' => $questionIds[$i], 'mepm_id' => trim($this->input->post("mepm_id")), 'meprm_updated_on' => date("Y-m-d H:i:s") ); } } else { $responseUpdateArray = array( 'meprm_sub_resp' => addslashes(trim($this->input->post("question" . $questionIds[$i]))), 'tspi_id' => $this->session->userdata("studentData")["stu_id"], 'qb_id' => $questionIds[$i], 'mepm_id' => trim($this->input->post("mepm_id")), 'meprm_updated_on' => date("Y-m-d H:i:s") ); } $this->TaskAndQuizManagement->updateNewStudentResponse($responseUpdateArray); } if ($i == sizeof($questionIds)) { $this->session->set_flashdata('successMessage', 'Model Paper Submitted Successfully.'); redirect("student/TasksAndQuizzes/"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Submitting Model Paper. Try Later.'); redirect("student/TasksAndQuizzes/"); } } } else { redirect("student/"); } } public function getModelPaperAttemptFullDetail() { $mepm_id = $_POST['mepm_id']; $tspi_id = $_POST['tspi_id']; $studentModelPaperAttempt = $this->TaskAndQuizManagement->getModelPaperAttemptResponseByStudent($tspi_id, $mepm_id)->result(); $studentAttemptInfo = array(); for ($i = 0; $i < sizeof($studentModelPaperAttempt); $i++) { if ($studentModelPaperAttempt[$i]->qg_id == "" || $studentModelPaperAttempt[$i]->qg_id == NULL) { $marksAwarded = ""; $isCorrect = ""; if ($studentModelPaperAttempt[$i]->meprm_obj_resp == $studentModelPaperAttempt[$i]->meprm_correct_resp) { $marksAwarded = $studentModelPaperAttempt[$i]->qb_marks; $isCorrect = true; } else { $marksAwarded = $studentModelPaperAttempt[$i]->qb_negative_marks; $isCorrect = false; } array_push($studentAttemptInfo, array( 'is_group_quest' => false, 'stu_id' => $tspi_id, 'mepm_id' => $mepm_id, 'qest_id' => $studentModelPaperAttempt[$i]->qb_id, 'qest_group_id' => '', 'qest_group' => '', 'qest_group_image' => '', 'qestion' => stripslashes($studentModelPaperAttempt[$i]->qb_question), 'qestion_image' => ($studentModelPaperAttempt[$i]->qb_image != NULL || $studentModelPaperAttempt[$i]->qb_image != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_image) . "'>" : "", 'opt_a' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_a), 'opt_a_img' => ($studentModelPaperAttempt[$i]->qb_opt_a_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_a_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_a_img) . "'>" : "", 'opt_b' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_b), 'opt_b_img' => ($studentModelPaperAttempt[$i]->qb_opt_b_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_b_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_b_img) . "'>" : "", 'opt_c' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_c), 'opt_c_img' => ($studentModelPaperAttempt[$i]->qb_opt_c_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_c_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_c_img) . "'>" : "", 'opt_d' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_d), 'opt_d_img' => ($studentModelPaperAttempt[$i]->qb_opt_d_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_d_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_d_img) . "'>" : "", 'correct_opt' => $studentModelPaperAttempt[$i]->qb_correct_opt, 'response' => $studentModelPaperAttempt[$i]->meprm_obj_resp, 'marks_awarded' => $marksAwarded, 'is_correct' => $isCorrect )); } else { $marksAwarded = ""; $isCorrect = ""; if ($studentModelPaperAttempt[$i]->meprm_obj_resp == $studentModelPaperAttempt[$i]->meprm_correct_resp) { $marksAwarded = $studentModelPaperAttempt[$i]->qb_marks; $isCorrect = true; } else { $marksAwarded = $studentModelPaperAttempt[$i]->qb_negative_marks; $isCorrect = false; } array_push($studentAttemptInfo, array( 'is_group_quest' => true, 'stu_id' => $tspi_id, 'mepm_id' => $mepm_id, 'qest_id' => $studentModelPaperAttempt[$i]->qb_id, 'qest_group_id' => $studentModelPaperAttempt[$i]->qg_id, 'qest_group' => stripslashes($studentModelPaperAttempt[$i]->qg_question), 'qest_group_image' => ($studentModelPaperAttempt[$i]->qg_image != NULL || $studentModelPaperAttempt[$i]->qg_image != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qg_image) . "'>" : "", 'qestion' => stripslashes($studentModelPaperAttempt[$i]->qb_question), 'qestion_image' => ($studentModelPaperAttempt[$i]->qb_image != NULL || $studentModelPaperAttempt[$i]->qb_image != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_image) . "'>" : "", 'opt_a' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_a), 'opt_a_img' => ($studentModelPaperAttempt[$i]->qb_opt_a_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_a_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_a_img) . "'>" : "", 'opt_b' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_b), 'opt_b_img' => ($studentModelPaperAttempt[$i]->qb_opt_b_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_b_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_b_img) . "'>" : "", 'opt_c' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_c), 'opt_c_img' => ($studentModelPaperAttempt[$i]->qb_opt_c_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_c_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_c_img) . "'>" : "", 'opt_d' => stripslashes($studentModelPaperAttempt[$i]->qb_opt_d), 'opt_d_img' => ($studentModelPaperAttempt[$i]->qb_opt_d_img != NULL || $studentModelPaperAttempt[$i]->qb_opt_d_img != "") ? "<img src='" . base_url($studentModelPaperAttempt[$i]->qb_opt_d_img) . "'>" : "", 'correct_opt' => $studentModelPaperAttempt[$i]->qb_correct_opt, 'response' => $studentModelPaperAttempt[$i]->meprm_obj_resp, 'marks_awarded' => $marksAwarded, 'is_correct' => $isCorrect )); } } $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'student_attempt_info' => $studentAttemptInfo ); echo json_encode($responseData); } public function checkSerialNumbers() { $srnos = $_POST['uidArray']; $queryByUID = $this->StockAndPurchaseManagement->getStockInfoBySrNos($srnos); $ifAlreadyExists = 0; if (sizeof($queryByUID->result())) { $ifAlreadyExists = 1; } else { $ifAlreadyExists = 0; } $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'if_exist' => $ifAlreadyExists ); echo json_encode($responseData); } /* Request Handlers For E-Contents & Related Stuffs */ public function eContents() { if ($this->sessionvalidator->isStudentLoggedIn()) { $econtents = $this->TaskAndQuizManagement->getAssignedEContentsByStudent($this->session->userdata("studentData")["stu_id"])->result(); $viewData['myEContents'] = $econtents; $this->load->view('student/assessment/econtents', $viewData); } else { redirect("student/"); } } }