관리-도구
편집 파일: CFCourse_quiz_stud_control.php
<?php if (!class_exists('CFCourse_quiz_stud_control')) { class CFCourse_quiz_stud_control { var $loader; var $course_ob; function __construct($arr) { $this->loader = $arr['loader']; $this->course_ob = $this->loader->load("course_control"); } public function getPlayedQuizData($play_id) { global $mysqli; global $dbpref; $table = $dbpref . "stud_quiz"; $sql = "SELECT * FROM `" . $table . "` WHERE `id`=" . $play_id; $row = $mysqli->query($sql); $rs = $row->fetch_assoc(); if ($rs->num_rows > 0) { ob_start(); echo '<div class="cf-course-card"> <div class="pt-4 text-center" style="border-bottom:1px solid #cccccc;background-color: #f7f7f7;color:#6f7174"> <h3>Result</h3> </div> <div class="w-100"> <div class="row" > <div class="col-md-4"> <div class="text-center text-primary cf-course-qresult-div"> <h5 >Question</h5> <div class="cf-course-label-6">10</div> </div> </div> <div class="col-md-4"> <div class="text-center text-primary cf-course-qresult-div"> <h5 class="text-primary">Answered</h5> <div class="cf-course-label-6">8</div> </div> </div> <div class="col-md-4"> <div class="text-center text-primary cf-course-qresult-div"> <h5 class="text-primary">Unanswered</h5> <div class="cf-course-label-6">2</div> </div> </div> </div> </div> <div style="border-top:1px solid #cccccc" class="px-4 py-3" id="after_check_delay_result"> <div class="pb-1"><span class="cf-course-label-6">Score Is: </span> 40 </div> <div class="pb-1" ><span class="cf-course-label-6">Percentage: </span> 80% </div> <div class="pb-1"><span class="cf-course-label-6">Time Spent: </span> 45s </div> <div class="pb-1"> You must study harder!</div> <div class="py-2 pt-5"> <button type="submit" class="btn btn-success btn-sm">Check Your Answers</button> <button type="submit" class="btn btn-primary mx-2 btn-sm">Try again</button> </div> </div> </div>'; $data = ob_get_clean(); } } public function checkIfIsAdmin($mid) { global $dbpref; global $mysqli; $data = [ "mid" => 0, "name" => "", "email" => "", "is_ad" => 0, "c_app" => -1, "adminT" => 'admin', "readed" => 0, "admin" => "" ]; $member = get_member($mid); $log_user = get_loggedin_user(); if (is_admin()) { $sql = "SELECT `id`,`pageid`,`name` FROM `" . $dbpref . "quick_member` WHERE `email`=" . $log_user['id'] . " ORDER BY `id` DESC"; $get_row = $mysqli->query($sql); $mem_data = $get_row->fetch_assoc(); if ($get_row->num_rows > 0) { if (($mem_data['pageid'] == "is_admin") && ($mem_data['name'] == "") && ($member['email'] == $log_user['email'])) { $data['mid'] = $mem_data['id']; $data['name'] = $log_user['name']; $data['email'] = $log_user['email']; $data['is_ad'] = 1; $data['c_app'] = 1; $data['adminT'] = 'admin'; $data['readed'] = 1; $data['admin'] = "admin"; } elseif ($member['email'] == $log_user['email']) { $data['mid'] = $mem_data['id']; $data['name'] = $log_user['name']; $data['email'] = $log_user['email']; $data['is_ad'] = 1; $data['c_app'] = 1; $data['adminT'] = 'admin'; $data['readed'] = 1; $data['admin'] = "admin"; } else { $data['mid'] = $member['id']; $data['name'] = $member['name']; $data['email'] = $member['email']; $data['is_ad'] = 0; $data['c_app'] = -1; $data['adminT'] = 'not'; $data['readed'] = 0; $data['admin'] = ""; } } else { $data['mid'] = $member['id']; $data['name'] = $log_user['name']; $data['email'] = $log_user['email']; $data['is_ad'] = 0; $data['c_app'] = -1; $data['adminT'] = 'not'; $data['readed'] = 0; $data['admin'] = ""; } } elseif ($log_user && ($log_user['permission'][0] == "admin" || in_array("cfcourse_preview", $log_user['permission']))) { $sql = "SELECT `id`,`pageid` FROM `" . $dbpref . "quick_member` WHERE `email`=" . $log_user['id'] . " ORDER BY `id` DESC"; $get_row = $mysqli->query($sql); $mem_data = $get_row->fetch_assoc(); if ($get_row->num_rows > 0) { if ($member) { $data['mid'] = $mem_data['id']; if ($member['email'] == $log_user['email']) { $data['mid'] = $mem_data['id']; $data['name'] = $log_user['name']; $data['email'] = $log_user['email']; $data['is_ad'] = 1; $data['c_app'] = 1; $data['adminT'] = 'admin'; $data['readed'] = 1; $data['admin'] = "admin"; } else { $data['mid'] = $member['id']; $data['name'] = $member['name']; $data['email'] = $member['email']; $data['is_ad'] = 0; $data['c_app'] = -1; $data['adminT'] = 'not'; $data['readed'] = 0; $data['admin'] = ""; // print_r( $member ); } } else { $data['mid'] = $member['id']; $data['name'] = $member['name']; $data['email'] = $member['email']; $data['is_ad'] = 0; $data['c_app'] = -1; $data['adminT'] = 'not'; $data['readed'] = 0; $data['admin'] = ""; } } else { $data['mid'] = $member['id']; $data['name'] = $member['name']; $data['email'] = $member['email']; $data['is_ad'] = 0; $data['c_app'] = -1; $data['adminT'] = 'not'; $data['admin'] = 'not'; $data['readed'] = 0; } } else { $data['mid'] = $member['id']; $data['name'] = $member['name']; $data['email'] = $member['email']; $data['is_ad'] = 0; $data['c_app'] = -1; $data['adminT'] = 'not'; $data['admin'] = 'not'; $data['readed'] = 0; } return $data; } //to control the ajax request public function getAjaxRequest(array $qdata) { global $mysqli; global $dbpref; if ($qdata['cfquiz_stud_param'] == "submit_quiz_response") { $quiz_id = cf_enc($mysqli->real_escape_string($qdata['cfquiz_quiz_id']), "decrypt"); $c_id = cf_enc($mysqli->real_escape_string($qdata['cfquiz_c_id']), "decrypt"); $s_id = cf_enc($mysqli->real_escape_string($qdata['cfquiz_s_id']), "decrypt"); $mem_id = cf_enc($mysqli->real_escape_string($qdata['cfquiz_mem_id']), "decrypt"); $time_spend = $mysqli->real_escape_string($qdata['time_spend']); $quiz_title = $mysqli->real_escape_string($qdata['cfquiz_title']); $quiz_desc = $mysqli->real_escape_string($qdata['cfquiz_desc']); $cfquiz_ques_counter = $mysqli->real_escape_string($qdata['cfquiz_ques_counter']); $ques_id = $qdata['cfquiz_ques_id']; $mem_data = self::checkIfIsAdmin($mem_id); $mid = $mem_data['mid']; $name = $mem_data['name']; $email = $mem_data['email']; $is_ad = $mem_data['is_ad']; $score = 0; $attempt_question = 0; $correct_an = []; for ($cou = 1; $cou <= $cfquiz_ques_counter; $cou++) { $qs_id = $mysqli->real_escape_string($ques_id[$cou - 1]); if (isset($qdata['opt@' . $qs_id])) { $attempt_question++; ${"opt$qs_id"} = $qdata['opt@' . $qs_id]; if (is_array(${"opt$qs_id"})) { $cans = join("@brk@", ${"opt$qs_id"}); } $correct_an[$qs_id] = $cans; $counter = 0; $qry = $this->read_all_correct_answers($quiz_id); while ($r = $qry->fetch_object()) { $counter++; if ($cans == $r->correct_options && $counter == $cou) //counter must be equal { $score++; } } //end of while-loop } } //end of for-loop $qry3 = $this->read_content_options($quiz_id); while ($r3 = $qry3->fetch_object()) { $replay_allowed = $r3->replay_allowed; $result_comments = $r3->result_comments; } $r_c = json_decode($result_comments, true); if (!empty($r_c) && count($r_c) > 0) { $count = count($r_c); $quiz_percentage = ($score / $cfquiz_ques_counter) * 100; foreach ($r_c as $r_com) { $start = $r_com['start']; $end = $r_com['end']; $text = $r_com['text']; if ($quiz_percentage >= $start && $quiz_percentage <= $end) { $quiz_per_comment = $text; break; } } } //$replay_allowed=1; $played_status = 1; //1 means this quiz is already played. $submitted_date = $mysqli->real_escape_string($qdata['sdate']); $result_out_date = $mysqli->real_escape_string($qdata['rdate']); $insert_date = $submitted_date; if ($time_spend == "no-limit") { $time_spent = "No Time Limit"; } else { $time_spent = $this->course_ob->getTime($time_spend); } $qry = $this->read_all_correct_answers($quiz_id); //before inserting needs to check if the quiz is already played or not $qry2 = $this->read_student_quiz_result($quiz_id, $mem_id, false); //if qry2 will give empty then only need to insert .. ortherwise do nothing .. $table_student_quiz = $dbpref . "stud_quiz"; $table_student_submit_quiz = $dbpref . "submit_quiz"; $un_attempt_question = $cfquiz_ques_counter - $attempt_question; $attempt = json_encode(array("answerd" => $attempt_question, "unanswerd" => $un_attempt_question)); if ($qry2->num_rows == 0) { $sql = "INSERT INTO `" . $table_student_quiz . "`(`member_id`, `course_id`,`name`,`email`,`quiz_title`,`quiz_description`, `quiz_id`,`no_correct_answers`, `no_of_questions`,`attempt_answer`, `percentage`, `comment`, `time_spent`, `played_status`, `replay_allowed`, `submitted_on`, `result_out_date`) VALUES ( $mid, $c_id,'" . $name . "','" . $email . "','" . $quiz_title . "','" . $quiz_desc . "',$quiz_id,'" . $score . "','" . $cfquiz_ques_counter . "','" . $attempt . "','" . $quiz_percentage . "','" . $quiz_per_comment . "','" . $time_spent . "','" . $played_status . "','" . $replay_allowed . "','" . $insert_date . "','" . $result_out_date . "')"; $total_count = getTotalCount($table_student_quiz); $site_token_for_dashboard = get_option('site_token'); if ($_SESSION['user_plan_type' . $site_token_for_dashboard] == 2 && $total_count >= 5) { $affected_rows = 0; } else { $mysqli->query($sql); $affected_rows = $mysqli->affected_rows; } if ($affected_rows > 0) { $response_id = isset($mysqli->insert_id) ? $mysqli->insert_id : 0; $cou = 0; while ($r = $qry->fetch_object()) { $cou++; if (isset($correct_an[$r->id])) { $cor_ans = $correct_an[$r->id]; $sql2 = "INSERT INTO `" . $table_student_submit_quiz . "`( `response_id`, `question_id`,`quiz_id`,`question_type`, `questions`, `options`, `correct_answer`, `student_answer`) VALUES ($response_id, $r->id, $quiz_id, $r->quiz_type, '" . $r->question . "','" . $r->options . "','" . $r->correct_options . "','" . $cor_ans . "')"; } else { $sql2 = "INSERT INTO `" . $table_student_submit_quiz . "`( `response_id`, `question_id`,`quiz_id`,`question_type`, `questions`, `options`, `correct_answer`, `student_answer`) VALUES ($response_id, $r->id, $quiz_id, $r->quiz_type, '" . $r->question . "','" . $r->options . "','" . $r->correct_options . "','')"; } $total_count = getTotalCount($table_student_submit_quiz); $site_token_for_dashboard = get_option('site_token'); if ($_SESSION['user_plan_type' . $site_token_for_dashboard] == 2 && $total_count >= 5) { $mysqli->query($sql2); } else { $mysqli->query($sql2); } } //end of while loop $data = $this->getSubmitQuizResponse($mid, $response_id, $quiz_id, $c_id, $result_out_date); echo json_encode(array("status" => 1, "message" => "success", "data" => $data, "op_id" => $quiz_id)); if (get_option('reply_assign_test_email') && get_option('reply_assign_test_email') == 1) { self::sendQuizEmail($c_id, $quiz_id, $name, $quiz_title, $submitted_date); } self::addProgress($mem_id, $quiz_id, $c_id, $s_id); die(); } else { echo json_encode(array("status" => 0)); die(); } } //end of if else if ($qry2->num_rows == 1) { //For update - do delete it first then reinsert it. $res = $this->delete_a_stud_response($mem_id, $quiz_id); if ($res == 1) { $sql = "INSERT INTO `" . $table_student_quiz . "`(`member_id`, `course_id`,`name`,`email`,`quiz_title`,`quiz_description`, `quiz_id`,`no_correct_answers`, `no_of_questions`,`attempt_answer`, `percentage`, `comment`, `time_spent`, `played_status`, `replay_allowed`, `submitted_on`, `result_out_date`) VALUES ( $mid, $c_id,'" . $name . "','" . $email . "','" . $quiz_title . "','" . $quiz_desc . "',$quiz_id,'" . $score . "','" . $cfquiz_ques_counter . "','" . $attempt . "','" . $quiz_percentage . "','" . $quiz_per_comment . "','" . $time_spent . "','" . $played_status . "','" . $replay_allowed . "','" . $insert_date . "','" . $result_out_date . "')"; $total_count = getTotalCount($table_student_quiz); $site_token_for_dashboard = get_option('site_token'); if ($_SESSION['user_plan_type' . $site_token_for_dashboard] == 2 && $total_count >= 5) { $affected_rows = 0; } else { $mysqli->query($sql); $affected_rows = $mysqli->affected_rows; } if ($affected_rows > 0) { $response_id = isset($mysqli->insert_id) ? $mysqli->insert_id : 0; while ($r = $qry->fetch_object()) { $total_count = getTotalCount($table_student_submit_quiz); $site_token_for_dashboard = get_option('site_token'); if ($_SESSION['user_plan_type' . $site_token_for_dashboard] == 2 && $total_count >= 5) { break; } if (isset($correct_an[$r->id])) { $cor_ans = $correct_an[$r->id]; $sql2 = "INSERT INTO `" . $table_student_submit_quiz . "`( `response_id`, `question_id`,`quiz_id`,`question_type`, `questions`, `options`, `correct_answer`, `student_answer`) VALUES ($response_id, $r->id, $quiz_id, $r->quiz_type, '" . $r->question . "','" . $r->options . "','" . $r->correct_options . "','" . $cor_ans . "')"; $mysqli->query($sql2); } else { $sql2 = "INSERT INTO `" . $table_student_submit_quiz . "`( `response_id`, `question_id`,`quiz_id`,`question_type`, `questions`, `options`, `correct_answer`, `student_answer`) VALUES ($response_id, $r->id, $quiz_id, $r->quiz_type, '" . $r->question . "','" . $r->options . "','" . $r->correct_options . "','')"; $mysqli->query($sql2); } } //end of while loop $data = $this->getSubmitQuizResponse($mid, $response_id, $quiz_id, $c_id, $result_out_date); echo json_encode(array("status" => 1, "message" => "success", "data" => $data, "op_id" => $quiz_id)); if (get_option('reply_assign_test_email') && get_option('reply_assign_test_email') == 1) { self::sendQuizEmail($c_id, $quiz_id, $name, $quiz_title, $submitted_date); } self::addProgress($mem_id, $quiz_id, $c_id, $s_id); die(); } else { echo json_encode(array("status" => 0)); die(); } } //end of if($res=1) } } //end of calculate_result //to compare answers.. if ($qdata['cfquiz_stud_param'] == "view_result") { $q_id = cf_enc($mysqli->real_escape_string($qdata['q_id']), "decrypt"); $add_times_ser = $mysqli->real_escape_string($qdata['date']); $qr_id = cf_enc($mysqli->real_escape_string($qdata['qr_id']), "decrypt"); $m_id = cf_enc($mysqli->real_escape_string($qdata['m_id']), "decrypt"); $no_of_days = $mysqli->real_escape_string($qdata['days']); $mem_data = self::checkIfIsAdmin($m_id); $mid = $mem_data['mid']; $assign_ob = $this->loader->load("assign_stud_control"); $qry = $this->read_student_quiz_result($q_id, $mid, $qr_id); $created_output = $this->create_output($q_id, $mid, $qr_id); $r = $qry->fetch_object(); $enable_days = $assign_ob->getAssignById($q_id, "delay_result"); $edays = (int)$enable_days['delay_result']; $result_out_date = $r->result_out_date; if ($no_of_days > 0 && $edays === 1) { echo json_encode(array("status" => "locked", "checked" => true, "no_of_days" => $no_of_days, "date" => $result_out_date)); die(); } else { if ($created_output['result']) { echo json_encode(array("status" => "unlocked", "no_of_days" => $no_of_days, "checked" => true, "status" => "unlocked", "result" => $created_output['result'], "option" => $created_output['option'])); } else { echo json_encode(array("no_of_days" => $no_of_days, "status" => "locked", "checked" => false)); } die(); } } //end of delay_result function } //end of ajax function function addProgress($mid, $oid, $cid, $sid) { global $mysqli; global $dbpref; $table = $dbpref . "member_progress"; $watch_c = 1; $stmt = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `option_id`=$oid AND `member_id`=" . $mid); if ($stmt->num_rows == 0) { $total_count = getTotalCount($table); $site_token_for_dashboard = get_option('site_token'); if ($_SESSION['user_plan_type' . $site_token_for_dashboard] == 2 && $total_count >= 5) { return; } $stmt = $mysqli->query("INSERT INTO `" . $table . "`( `course_id`, `section_id`, `option_id`, `member_id`, `progress`) VALUES ( $cid, $sid, $oid, $mid, $watch_c )"); } } function sendQuizEmail($quiz_id, $cid, $name, $title, $time) { $email_body = "<p>Hello,</p>"; $com_email = get_option("communication_email"); $subject = "(CourseFunnels) Quiz Notification"; $newurl = get_option("install_url") . "?page=cfcourse_quiz_response&cfcourse_id=" . $cid . "&cfcontent_id=" . $quiz_id; $email_body .= "<p>I hope you’re having a great week. <strong>" . $name . "</strong> has played the Quiz <strong>" . $title . "</strong> at " . $time . ".</p>"; $email_body .= "<p><a target='_blank' href='" . $newurl . "'>See</a> </p>"; $email_body .= "<p>Thanks </p><p>CourseFunnels</p>"; $email_data = [ "", "name" => "", "email" => $com_email, "subject" => $subject, "body" => $email_body ]; cf_mail($email_data); } public function getSubmitQuizResponse($m_id, $qr_id, $q_id, $c_id, $result_out_date) { $b_m_id = $m_id; $b_qr_id = $qr_id; $b_q_id = $q_id; $b_c_id = $c_id; $quiz_data = $this->course_ob->get_quiz_by_id($q_id); $m_id = cf_enc($m_id, "encrypt"); $qr_id = cf_enc($qr_id, "encrypt"); $q_id = cf_enc($q_id, "encrypt"); $c_id = cf_enc($c_id, "encrypt"); $cert_button = ""; if ($quiz_data && isset($quiz_data['show_cert']) && (int)$quiz_data['show_cert'] === 1 && $this->course_ob->isResultPublished($quiz_data['id'], $b_m_id, 'quiz')) { $cert_button = '<form action="" method="POST" style="display: inline;"> <input type="hidden" name="cfcourse_cert_exam_type" value="quiz"> <input type="hidden" name="cfcourse_cert_exam_id" value="' . cf_enc($quiz_data['id']) . '"> <input type="hidden" name="cfcourse_cert_res_id" value="' . $qr_id . '"> <button name="export_cert_for_exam" type="submit" class="btn btn-sm btn-info"><i class="fas fa-certificate"></i> Download Certificate</button> </form>'; } $html = ' <div class="rounded border mt-5 pt-5 text-center"> <h5>Thanks for playing quiz!</h5> <div class="pb-5 pt-2"> <button type="submit" data-mid="' . $m_id . '" data-qrid="' . $qr_id . '" data-date="' . $result_out_date . '" data-qid="' . $q_id . '" data-cid="' . $c_id . '" class="btn btn-success btn-sm cf-course-view-qresult" data="">View Result</button> ' . $cert_button . ' </div> </div> '; return $html; } //this function is used to create the output of the played quiz questions.. public function create_output($quiz_id, $mem_id, $qr_id) { global $mysqli; global $dbpref; $table1 = $dbpref . "submit_quiz"; $table = $dbpref . "stud_quiz"; $sql = "SELECT * FROM `" . $table . "` WHERE `quiz_id`=$quiz_id AND `member_id`=$mem_id AND `id`=$qr_id"; $qry = $mysqli->query($sql); $result_data = ''; if ($qry->num_rows == 0) { echo '<div class="col-sm-12"> <h4 class="text-center" style="opacity:0.8;">No Questions Found</h4> </div>'; } else { $rd = $qry->fetch_assoc(); $attempt = json_decode($rd['attempt_answer'], true); $answerd = $attempt['answerd']; $unanswerd = $attempt['unanswerd']; $total_question = $rd['no_of_questions']; $correct_answer = $rd['no_correct_answers']; $percentage = $rd['percentage']; $time_spent = $rd['time_spent']; $comment = $rd['comment']; $quiz_data = $this->course_ob->get_quiz_by_id($quiz_id); $cert_button = ""; if ($quiz_data && isset($quiz_data['show_cert']) && (int)$quiz_data['show_cert'] === 1 && $this->course_ob->isResultPublished($quiz_data['id'], $mem_id, 'quiz')) { $cert_button = ' <div class="mx-auto my-4 cf_course_start_quiz_div"> <form action="" method="POST" style="display: inline;"> <input type="hidden" name="cfcourse_cert_exam_type" value="quiz"> <input type="hidden" name="cfcourse_cert_exam_id" value="' . cf_enc($quiz_data['id']) . '"> <input type="hidden" name="cfcourse_cert_res_id" value="' . cf_enc($qr_id) . '"> <button name="export_cert_for_exam" type="submit" class="btn btn-sm btn-info"><i class="fas fa-certificate"></i> Download Certificate</button> </form> </div> '; } if ($rd['replay_allowed'] == 1) { $plya_again = '<div class="mx-auto my-4 cf_course_start_quiz_div"> <button type="button" id="cf_course_start_quiz" class="btn btn-sm cf_course_start_quiz btn-primary" data-duration="' . $quiz_data['duration'] . '">Play Again!! </button> </div>'; } else { $plya_again = ""; } $result_data .= ' <div class="cf-course-card"> <div class="pt-4 text-center" style="border-bottom:1px solid #cccccc;background-color: #f7f7f7;color:#6f7174"> <h3>Result</h3> </div> <div class="w-100"> <div class="row" > <div class="col-md-4"> <div class="text-center text-primary cf-course-qresult-div"> <h5 >Question</h5> <div class="cf-course-label-6">' . $total_question . '</div> </div> </div> <div class="col-md-4"> <div class="text-center text-primary cf-course-qresult-div"> <h5 class="text-primary">Answered</h5> <div class="cf-course-label-6">' . $answerd . '</div> </div> </div> <div class="col-md-4"> <div class="text-center text-primary cf-course-qresult-div"> <h5 class="text-primary">Unanswered</h5> <div class="cf-course-label-6">' . $unanswerd . '</div> </div> </div> </div> </div> <div style="border-top:1px solid #cccccc" class="px-4 py-3" id="after_check_delay_result"> <div class="pb-1"><span class="cf-course-label-6">Correct Answer: </span> ' . $correct_answer . ' </div> <div class="pb-1" ><span class="cf-course-label-6">Percentage: </span>' . $percentage . '% </div> <div class="pb-1"><span class="cf-course-label-6">Time Spent: </span> ' . $time_spent . ' </div> <div class="pb-1"> ' . $comment . '</div> ' . $plya_again . $cert_button . ' </div> </div> '; $sql1 = "SELECT * FROM `" . $table1 . "` WHERE `response_id`=" . $rd['id']; $qry1 = $mysqli->query($sql1); $count = 0; $assignment_ob = $this->loader->load("assignment_control"); $question_option = ""; while ($r = $qry1->fetch_assoc()) { $count++; $j = 0; $question = $assignment_ob->replaceBetweenString(base64_decode($r['questions']), "{{code}}", "{{/code}}"); $options = json_decode($r['options'], true); $question = html_entity_decode($question); $a_correct_ans = $r['correct_answer']; $s_correct_ans = $r['student_answer']; ob_start(); ?> <div class="card my-2 p-3"> <?php if (empty($s_correct_ans)) { ?> <div class="d-flex text-danger text-left py--2"> <div class="cf-course-first-div"> <span style="font-weight:600">Q <?= $count; ?>. </span> </div> <div style="font-weight:500;width:100%"><?= $question; ?></div> </div> <?php } else { ?> <div class="d-flex text-left py-2"> <div class="cf-course-first-div"> <span style="font-weight:600">Q <?= $count; ?>. </span> </div> <div style="font-weight:500;width:100%"><?= $question; ?></div> </div> <?php } ?> <div class="mb-3 text-left py-0"> <?php foreach ($options as $opt => $opt_value) { $j++; if (!empty($s_correct_ans)) { ?> <?php if ($a_correct_ans == $s_correct_ans) : ?> <?php if ((strpos($s_correct_ans, $opt) !== false) && (strpos($a_correct_ans, $opt) !== false)) : ?> <div class="d-flex text-success"> <div class="cf-co-quiz-opt1 me-2"> <span><i class="fas fa-check"></i></span> </div> <div class="cf-co-quiz-opt2 "><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php else : ?> <div class="d-flex "> <div class="cf-co-quiz-opt1 me-2"></div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php endif; ?> <?php else : ?> <?php if (strpos($s_correct_ans, $opt) !== false) : ?> <div class="d-flex text-danger"> <div class="cf-co-quiz-opt1 me-2"> <span><i class="fas fa-times"></i></span> </div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php elseif (strpos($a_correct_ans, $opt) !== false) : ?> <div class="d-flex text-success"> <div class="cf-co-quiz-opt1 me-2"> <span><i class="fas fa-check"></i></span> </div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php else : ?> <div class="d-flex "> <div class="cf-co-quiz-opt1 me-2"><span></div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php endif; ?> <?php endif; ?> <?php } else { ?> <?php if (strpos($s_correct_ans, $opt) !== false) : ?> <div class="d-flex text-danger"> <div class="cf-co-quiz-opt1 me-2"> <span><i class="fas fa-times"></i></span> </div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php elseif (strpos($a_correct_ans, $opt) !== false) : ?> <div class="d-flex text-success"> <div class="cf-co-quiz-opt1 me-2"> <span><i class="fas fa-check"></i></span> </div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php else : ?> <div class="d-flex "> <div class="cf-co-quiz-opt1 me-2"><span></div> <div class="cf-co-quiz-opt2"><span> <?= $j; ?></span> <?= htmlentities(base64_decode($opt_value)); ?></div> </div> <?php endif; ?> <?php } } ?> <?php if (empty($s_correct_ans)) { echo '<div class="text-danger mt-3">Not Answered.</div>'; } else { echo '<div class="text-success mt-3"> Answered.</div>'; } ?> </div> </div> <?php $question_option .= ob_get_clean(); } //while loop over here $question_option .= $plya_again; if ($quiz_data['admin_check']) { if ($rd['checked'] == 1) { $result_data = $result_data; } else { $result_data = false; } } else { $result_data = $result_data; } // echo $result_data; return array("result" => $result_data, "option" => $question_option); } //else part now over } //function create output ends here //this table is to read the quiz result from the table. public function read_student_quiz_result($quiz_id, $member_id, $qr_id = false) { global $mysqli; global $dbpref; $table_student_quiz = $dbpref . "stud_quiz"; $cond = ""; if ($qr_id) { $cond = " AND `id`=" . $qr_id; } $qry = $mysqli->query("SELECT * FROM `" . $table_student_quiz . "` WHERE `quiz_id`=$quiz_id AND `member_id`=$member_id" . $cond); return $qry; } //this function is used in view quiz response area for admin to view all the students who played quiz.. public function read_student_quiz_response($quiz_id) { global $mysqli; global $dbpref; $table_student_quiz = $dbpref . "stud_quiz"; $table_member = $dbpref . "quick_member"; $cond = ""; if ($quiz_id) { $quiz_id = $mysqli->real_escape_string($quiz_id); $cond = " where `quiz_id`=" . $quiz_id; } $make_sql = "SELECT DISTINCT sq.`member_id`,sq.`course_id`,sq.`section_id`,sq.`quiz_id`,sq.`no_correct_answers`,sq.`no_of_questions`,sq.`percentage`,sq.`comment`,sq.`time_spent`, sq.`submitted_on`,tm.`name`,tm.`email` FROM `" . $table_student_quiz . "` AS `sq` INNER JOIN `" . $table_member . "` AS `tm` ON sq.`member_id`=tm.`id` " . $cond; $qry = $mysqli->query($make_sql); return $qry; } //to delete a student quiz response from the admin side.. function delete_a_stud_response($member_id, $quiz_id) { global $mysqli; global $dbpref; $table = $dbpref . 'stud_quiz'; $member_id = $mysqli->real_escape_string($member_id); $result = $mysqli->query("delete from `" . $table . "` where `member_id`=" . $member_id . " and `quiz_id`=" . $quiz_id . ";"); return $result; } public function read_all_correct_answers($quiz_id) { global $mysqli; global $dbpref; $table = $dbpref . 'quiz_questions'; $cond = ""; if ($quiz_id) { $quiz_id = $mysqli->real_escape_string($quiz_id); $cond = " where `quiz_id`=" . $quiz_id; } $qry = $mysqli->query("SELECT `id`, `quiz_id`,`question`,`options`,`quiz_type`,`correct_options`,`quiz_type` FROM `" . $table . "`" . $cond); return $qry; } public function read_content_options($quiz_id) { global $mysqli; global $dbpref; $table = $dbpref . 'content_options'; $cond = ""; if ($quiz_id) { $quiz_id = $mysqli->real_escape_string($quiz_id); $cond = " WHERE `id`=" . $quiz_id; } $qry = $mysqli->query("SELECT * FROM `" . $table . "`" . $cond); return $qry; } function getAllSubQuizzes($total_quiz = false, $max_limit = false, $page = 1, $course_id = false, $quiz_id = false, $all = 0, $filter = 0) { global $mysqli; global $dbpref; $table = $dbpref . 'stud_quiz'; $table2 = $dbpref . 'all_products'; $table3 = $dbpref . 'content_options'; $page = $mysqli->real_escape_string($page); if (!$max_limit) { $max_limit = $mysqli->real_escape_string($max_limit); } $arr = array(); $limit = ""; if ($max_limit !== false && is_numeric($max_limit) && is_numeric($page)) { $page = ($page * $max_limit) - $max_limit; $limit = " limit " . $page . ',' . $max_limit; } $search = ""; if (isset($_POST['onpage_search'])) { $search = trim($mysqli->real_escape_string($_POST['onpage_search'])); $search = str_replace('_', '[_]', $search); $search = str_replace('%', '[%]', $search); $quiz = $mysqli->real_escape_string(htmlspecialchars($search)); $search = " AND cfq.`name` LIKE '%" . $quiz . "%' OR cfc.`title` LIKE '%" . $quiz . "%' OR cfoc.`title` LIKE '%" . $quiz . "%'"; } $order_by = " cfq.`id` desc"; if (isset($_GET['arrange_records_order'])) { $order_by = base64_decode($_GET['arrange_records_order']); } $date_between = dateBetween('added_on', null, true); if (strlen($date_between[0]) > 0) { $date_mid = $date_between[1]; $search .= $date_mid; } if ($course_id) { $search .= " AND cfq.`course_id`=" . $course_id; } if ($filter) { if ($filter == "r") { $search .= " AND cfq.`reply`=1"; } else if ($filter == "nr") { $search .= " AND cfq.`reply`=0"; } else if ($filter == "cq") { $search .= " AND cfq.`checked`=1"; } else if ($filter == "uncq") { $search .= " AND cfq.`checked`=0"; } } if ($quiz_id) { $search .= " AND cfq.`quiz_id`=" . $quiz_id; } $sql_dtebtw = "SELECT cfq.*, cfc.title AS 'course_name', cfoc.title AS 'quiz_name' FROM `" . $table . "` AS cfq LEFT JOIN `" . $table2 . "` as cfc ON cfc.`id`=cfq.`course_id` LEFT JOIN `" . $table3 . "` as cfoc ON cfq.`quiz_id`=cfoc.`id` WHERE 1" . $search . " ORDER BY " . $order_by . $limit; $qry = $mysqli->query($sql_dtebtw); $arr = []; if ($qry == null) { return 0; } else { if ($qry->num_rows > 0) { while ($data = $qry->fetch_assoc()) { $arr[] = $data; } } return $arr; } } function getSubQuizzesCount($course_id = false) { global $mysqli; global $dbpref; $table = $dbpref . 'stud_quiz'; $where = ""; if ($course_id) { $where .= " `course_id` = " . $course_id . " AND "; } $where .= " 1"; $qry = $mysqli->query("SELECT COUNT(`id`) AS `total_quiz` FROM `" . $table . "` WHERE " . $where); if ($qry == null) { return 0; } else { $r = $qry->fetch_object(); return $r->total_quiz; } } public function BulkQuizAction($allData) { global $mysqli; global $dbpref; $bulkac = $mysqli->real_escape_string($allData['bulkac']); $bulkval = $mysqli->real_escape_string($allData['bulkval']); $data = $allData['data']; if ($bulkval == "del") { self::quizDelete($data); } else if ($bulkval == "ch") { self::quizChecked($data, "c", false); } else if ($bulkval == "uch") { self::quizChecked($data, "uc", false); } } public function quizDelete($datas, $onlyone = false) { global $mysqli; global $dbpref; $table = $dbpref . "stud_quiz"; $return_del = 0; if ($onlyone === true) { $id = $mysqli->real_escape_string(trim($datas['id'])); $sql = "DELETE FROM `" . $table . "` WHERE `id`=" . $id; $return_del = $mysqli->query($sql) ? 1 : -1; } else { $data = array_reverse(explode(",", $datas[0])); $len = count($data); for ($i = 1; $i < $len; $i++) { $id = $mysqli->real_escape_string(trim($data[$i])); $sql = "DELETE FROM `" . $table . "` WHERE `id`=" . $id; $return_del = $mysqli->query($sql) ? 1 : -1; } } if ($return_del) { echo json_encode(array("msg" => "deleted", "status" => "1")); } else { echo json_encode(array("msg" => "not deleted", "status" => "0")); } die(); } public function quizChecked($datas, $bulkac, $onlyone = false) { global $mysqli; global $dbpref; $table = $dbpref . "stud_quiz"; $return_del = 0; if ($onlyone === true) { $id = (int)$mysqli->real_escape_string(trim($datas['id'])); $check = $mysqli->real_escape_string($datas['check']); $checked = $check == 0 ? 1 : 0; $sql = "UPDATE `" . $table . "` SET `checked`=$checked WHERE `id`=" . $id; $return_del = $mysqli->query($sql) ? 1 : -1; } else { $data = array_reverse(explode(",", $datas[0])); $len = count($data);; for ($i = 1; $i < $len; $i++) { $id = (int)$mysqli->real_escape_string(trim($data[$i])); if ($bulkac == "c") //c==checked { $sql = "UPDATE `" . $table . "` SET `checked`=1 WHERE `id`=" . $id; $return_del = $mysqli->query($sql) ? 1 : -1; } else if ($bulkac == "uc") //uc==unchecked { $sql = "UPDATE `" . $table . "` SET `checked`=0 WHERE `id`=" . $id; $return_del = $mysqli->query($sql) ? 1 : -1; } } } if ($return_del) { if ($bulkac == "ch") { echo json_encode(array("msg" => "checked all quiz successfully", "status" => "1")); } elseif ($bulkac == "uc") { echo json_encode(array("msg" => "unchecked all quiz successfully", "status" => "1")); } else { echo json_encode(array("msg" => "checked all quiz successfully", "status" => "1")); } } else { if ($bulkac == "ch") { echo json_encode(array("msg" => "not checked all quiz successfully", "status" => "0")); } elseif ($bulkac == "uc") { echo json_encode(array("msg" => "not unchecked all quiz successfully", "status" => "0")); } else { echo json_encode(array("msg" => "not checked all quiz successfully", "status" => "0")); } } die(); } function replyBulkCheckedQuiz($data) { global $mysqli; global $dbpref; $sends_email = 0; $incorrect_email = []; $email_body = $mysqli->real_escape_string($data['email_content']); $group_size = $mysqli->real_escape_string($data['group_size']); $start = $mysqli->real_escape_string($data['start']); $end = $mysqli->real_escape_string($data['end']); $subject = $mysqli->real_escape_string($data['title']); $name = $mysqli->real_escape_string($data['name']); $email = $mysqli->real_escape_string($data['email']); $cname = $mysqli->real_escape_string($data['cname']); $aid = $mysqli->real_escape_string($data['aid']); $qname = $mysqli->real_escape_string($data['qname']); $data_id = array_reverse(explode(",", $aid)); $data_name = array_reverse(explode("@brk@", $name)); $data_email = array_reverse(explode("@brk@", $email)); $data_cname = array_reverse(explode("@brk@", $cname)); $data_qname = array_reverse(explode("@brk@", $qname)); $len = count($data_id); $totel_email = $len - 1; $sent_email = 0; $pending_email = 0; for ($i = $start; $i <= $end; $i++) { if (isset($data_email[$i]) && !empty($data_email[$i])) { $s_name = $mysqli->real_escape_string($data_name[$i]); $s_email = $mysqli->real_escape_string($data_email[$i]); $s_assign_name = $mysqli->real_escape_string($data_qname[$i]); $s_course_name = $mysqli->real_escape_string($data_cname[$i]); // echo $s_name; if (filter_var($s_email, FILTER_VALIDATE_EMAIL) === false) { echo json_encode(array("status" => 2, "msg" => "Incorrect Email", "email" => $s_email)); die(); } //for name search if (stristr($subject, "{name}")) { $subject = str_ireplace("{name}", $s_name, $subject); } if (stristr($subject, "{quiz_name}")) { $subject = str_ireplace("{quiz_name}", $s_assign_name, $subject); } if (stristr($subject, "{course_name}")) { $subject = str_ireplace("{course_name}", $s_course_name, $subject); } //for email body search if (stristr($email_body, "{name}")) { $email_body = str_ireplace("{name}", $s_name, $email_body); } if (stristr($email_body, "{quiz_name}")) { $email_body = str_ireplace("{quiz_name}", $s_assign_name, $email_body); } if (stristr($email_body, "{course_name}")) { $email_body = str_ireplace("{course_name}", $s_course_name, $email_body); } $subject = stripcslashes(str_replace(array("\n\r", "\n", "\r"), PHP_EOL, $subject)); $email_body = stripcslashes(str_replace(array("\n\r", "\n", "\r"), PHP_EOL, $email_body)); $data = [ "", "name" => $s_name, "email" => $s_email, "subject" => $subject, "body" => $email_body ]; $sends_email = cf_mail($data); $reply_data = json_encode(array("subject" => $subject, "body" => $email_body)); $id = $mysqli->real_escape_string($data_id[$i]); $sql = "UPDATE `" . $dbpref . "stud_quiz` SET `reply`=1, `reply_data`='" . $reply_data . "' WHERE `id`=$id"; $ret = $mysqli->query($sql); $sent_email = $i; $pending_email = $totel_email - $sent_email; } } if ($sends_email) { echo json_encode(array("totel_mail" => $totel_email, "sent_email" => $sent_email, "pending_email" => $pending_email, "pending" => "yes", "status" => 1, "msg" => "record found")); } else { echo json_encode(array("status" => 0, "msg" => "emails not sent successfully")); } die(); } function replyCheckedQuiz($data) { global $mysqli; global $dbpref; $s_name = $mysqli->real_escape_string($data['name']); $s_course_name = $mysqli->real_escape_string($data['cname']); $s_assign_name = $mysqli->real_escape_string($data['aname']); $email = $mysqli->real_escape_string($data['email']); $email = $mysqli->real_escape_string($data['email']); if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { echo json_encode(array("status" => 2, "msg" => "Incorrect Email")); die(); } $email_body = $mysqli->real_escape_string($data['email_content']); $subject = $mysqli->real_escape_string($data['title']); //for name search if (stristr($subject, "{name}")) { $subject = str_ireplace("{name}", $s_name, $subject); } if (stristr($subject, "{quiz_name}")) { $subject = str_ireplace("{quiz_name}", $s_assign_name, $subject); } if (stristr($subject, "{course_name}")) { $subject = str_ireplace("{course_name}", $s_course_name, $subject); } //for email body search if (stristr($email_body, "{name}")) { $email_body = str_ireplace("{name}", $s_name, $email_body); } if (stristr($email_body, "{quiz_name}")) { $email_body = str_ireplace("{quiz_name}", $s_assign_name, $email_body); } if (stristr($email_body, "{course_name}")) { $email_body = str_ireplace("{course_name}", $s_course_name, $email_body); } $subject = stripcslashes(str_replace(array("\n\r", "\n", "\r"), PHP_EOL, $subject)); $email_body = stripcslashes(str_replace(array("\n\r", "\n", "\r"), PHP_EOL, $email_body)); $edata = [ "", "name" => $s_name, "email" => $email, "subject" => $subject, "body" => $email_body ]; $send_email = cf_mail($edata); if ($send_email) { $reply_data = json_encode(array("subject" => $subject, "body" => $email_body)); $id = $mysqli->real_escape_string($data['rid']); $sql = "UPDATE `" . $dbpref . "stud_quiz` SET `reply`=1, `reply_data`='" . $reply_data . "' WHERE `id`=$id"; $ret = $mysqli->query($sql); if ($ret) { echo json_encode(array("status" => 1, "msg" => "email sent successfully")); } else { echo json_encode(array("status" => 1, "msg" => "email sent successfully")); } } else { echo json_encode(array("status" => 0, "msg" => "email sent successfully")); } die(); } function addCheckQuiz($data) { global $mysqli; global $dbpref; $table1 = $dbpref . 'stud_quiz'; $table2 = $dbpref . 'submit_quiz'; $rid = trim($mysqli->real_escape_string($data['rid'])); $sql = "UPDATE `" . $table1 . "` SET `checked`=1 WHERE `id`=" . $rid; $row_update = $mysqli->query($sql) ? 1 : -1; if ($row_update) { echo json_encode(array("status" => 1, "message" => "udpated")); } else { echo json_encode(array("status" => 0, "message" => "not udpated")); } } function ShowQuizResponse($rdata) { $training_ob = $this->loader->load('training_control'); $assignment_ob = $this->loader->load('assignment_control'); global $mysqli; global $dbpref; if (isset($_REQUEST['qrid']) && isset($_REQUEST['mid'])) { $student_quiz = $dbpref . "stud_quiz"; // in this table only percentage, scror , kab submit, kiya name, email etc enter honge $quiz_response = $dbpref . "submit_quiz"; // in this table only all question, unke correct answer, and student ke answer hoge enter hoge $content_table = $dbpref . "content_options"; $course_table = $dbpref . "all_products"; $qr_id = $mysqli->real_escape_string($rdata['qrid']); $sql = "SELECT cfsq.*, cfc.`title`, cfq.`title` as 'quiz_title' FROM `" . $student_quiz . "` as cfsq LEFT JOIN `" . $course_table . "` as cfc ON cfc.`id`=cfsq.`course_id` LEFT JOIN `" . $content_table . "` as cfq ON cfq.`id`=cfsq.`quiz_id` WHERE cfsq.`id`=" . $qr_id; $row = $mysqli->query($sql); if ($row->num_rows > 0) { $data = $row->fetch_assoc(); $make_sql = "SELECT cfqr.* FROM `" . $student_quiz . "` cfsq LEFT JOIN `" . $quiz_response . "` cfqr ON cfsq.`id`=cfqr.`response_id` WHERE cfsq.`id`=" . $qr_id; $qry = $mysqli->query($make_sql); // print_r($mysqli); $target_dir = plugin_dir_path(dirname(__FILE__, 1)); $target_url = plugin_dir_url(dirname(__FILE__, 1)); $prismfile = $target_url . "assets/js/prism.js"; ob_start(); require $target_dir . "views/view_quiz_response.php"; $data = ob_get_clean(); $data .= "<link rel='stylesheet' href='" . $target_url . "assets/css/prism.css'>"; $data .= "<script src='" . $prismfile . "'></script>"; echo json_encode(array("prism" => $prismfile, "status" => 1, "data" => $data)); } else { echo json_encode(array("status" => 2, "msg" => "No Dataf Found")); die(); } } else { echo json_encode(array("status" => 2, "msg" => "No Data dFound")); } } } } ?>