관리-도구
편집 파일: CFCourse_assign_stud_control.php
<?php //This class is created to display user/student the assignment inside the div... if (!class_exists('CFCourse_assign_stud_control')) { class CFCourse_assign_stud_control { public $loader; public $course_ob; function __construct($arr) { $this->loader = $arr['loader']; $this->course_ob = $this->loader->load("course_control"); } //function to view single assignment from content_options table by id function get_assign_by_id($assign_id) { global $mysqli; global $dbpref; $table = $dbpref . 'content_options'; $assign_id = trim($mysqli->real_escape_string($assign_id)); $r = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `id`=" . $assign_id); if ($r->num_rows > 0) { $data = $r->fetch_assoc(); return $data; } } // this function will return all details of content function getAssignById($oid, $get_only = false) { global $mysqli; global $dbpref; $op_id = $mysqli->real_escape_string($oid); $table = $dbpref . "content_options"; if ($get_only) { $qr = "SELECT `" . $get_only . "` FROM `" . $table . "` WHERE `id`=" . $op_id; } else { $qr = "SELECT * FROM `" . $table . "` WHERE `id`=" . $op_id; } $cresult = $mysqli->query($qr); if ($cresult->num_rows > 0) { $o_data = $cresult->fetch_assoc(); return $o_data; } } function showAssignmentReponse($rdata) { global $mysqli; global $dbpref; if (isset($_REQUEST['arid']) && isset($_REQUEST['mid'])) { $training_ob = $this->loader->load("training_control"); $assignment_ob = $this->loader->load("assignment_control"); $student_assign = $dbpref . "stud_assignment"; $assign_response = $dbpref . "submit_assignment"; $assign_table = $dbpref . "assignment"; $course_table = $dbpref . "all_products"; $ar_id = $mysqli->real_escape_string($rdata['arid']); $member_id = $mysqli->real_escape_string($rdata['mid']); $course_id = $mysqli->real_escape_string($rdata['cid']); $sql = "SELECT cfsa.*, cfc.`title` FROM `" . $student_assign . "` as cfsa LEFT JOIN `" . $course_table . "` as cfc ON cfc.`id`=cfsa.`course_id` WHERE cfsa.`id`=" . $ar_id; $row = $mysqli->query($sql); if ($row->num_rows > 0) { $data = $row->fetch_assoc(); $make_sql = "SELECT cfsr.* FROM `" . $student_assign . "` cfsa LEFT JOIN `" . $assign_response . "` cfsr ON cfsa.`id`=cfsr.`response_id` WHERE cfsa.`id`=" . $ar_id; $qry = $mysqli->query($make_sql); $target_dir = plugin_dir_path(dirname(__FILE__, 1)); $plugin_url = plugin_dir_url(dirname(__FILE__, 3)); $plugin_url = rtrim($plugin_url, "/"); $prismfile = $plugin_url . "/assets/js/prism.js"; ob_start(); require $target_dir . "views/view_assign_response.php"; $data = ob_get_clean(); $data .= "<link rel='stylesheet' href='" . $plugin_url . "/assets/css/prism.css'>"; $data .= "<script src='" . $prismfile . "'></script>"; echo json_encode(array("prism" => $prismfile, "status" => 1, "data" => $data)); die(); } else { echo json_encode(array("status" => 2, "msg" => "No Data Found")); die(); } } else { echo json_encode(array("status" => 2, "msg" => "No Data Found")); die(); } } //function to view single assignment details from table assignment by id function get_assign_details_by_id($assign_id) { global $mysqli; global $dbpref; $table = $dbpref . 'assignment'; $assign_id = trim($mysqli->real_escape_string($assign_id)); $r = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `assign_id`=" . $assign_id); if ($r->num_rows > 0) { $data = $r->fetch_assoc(); return $data; } } function addCheckAssignment($data) { global $mysqli; global $dbpref; $table1 = $dbpref . 'stud_assignment'; $table2 = $dbpref . 'submit_assignment'; $ar_id = trim($mysqli->real_escape_string($data['ar_id'])); $assign_id = trim($mysqli->real_escape_string($data['assign_id'])); $mid = trim($mysqli->real_escape_string($data['mid'])); $cid = trim($mysqli->real_escape_string($data['cid'])); $right = 0; $wrong = 0; $total = 0; if (isset($data['rightwrong'])) { foreach ($data['rightwrong'] as $key => $rightwrong) { $total++; $k = trim($mysqli->real_escape_string($key)); $rw = trim($mysqli->real_escape_string($rightwrong)); if ($rightwrong == "r") { $right++; } elseif ($rightwrong == "w") { $wrong++; } $sql1 = "UPDATE `" . $table2 . "` SET `checked`='" . $rw . "' WHERE `id`=$k"; $mysqli->query($sql1) ? 1 : -1; } } $r3 = self::get_assign_by_id($assign_id); $result_comments = $r3['result_comments']; $r_c = json_decode($result_comments, true); $percentage = ($right / $total) * 100; $percentage = round($percentage, 2); $comment = ""; if (!empty($r_c) && count($r_c) > 0) { foreach ($r_c as $r_com) { $start = $r_com['start']; $end = $r_com['end']; $text = $r_com['text']; if ($percentage >= $start && $percentage <= $end) { $comment .= $text; break; } } } $sql = "UPDATE `" . $table1 . "` SET `no_correct_answers`=$right, `comment`='" . $comment . "', `percentage`=$percentage, `wrong_answers`=$wrong, `checked`=1 WHERE `id`=$ar_id AND `member_id`=$mid"; $row_update = $mysqli->query($sql) ? 1 : -1; if ($row_update) { $sql2 = "SELECT * FROM `" . $table1 . "` WHERE `id`=$ar_id AND `member_id`=$mid"; $row = $mysqli->query($sql2); $data = $row->fetch_assoc(); $html = ' <p class="card-text"> <span class="cf-course-label-5">Total Questions : </span> ' . $data['no_of_questions'] . '<br> <span class="cf-course-label-5"> Correct Answer : </span> ' . $data['no_correct_answers'] . '<br> <span class="cf-course-label-5"> Percentage Received : </span> ' . $data['percentage'] . "%" . '<br> <span class="cf-course-label-5"> Comments Received : </span> ' . $data['comment'] . '<br> <span class="cf-course-label-5"> Time Spent : </span> ' . $data['time_spent'] . '<br> <span class="cf-course-label-5"> Submitted On : </span> ' . $data['submitted_on'] . ' </p>'; echo json_encode(array("status" => 1, "message" => "udpated", "data" => $html, "arid" => $ar_id, "check" => true)); die(); } else { echo json_encode(array("status" => 0, "message" => "not udpated", "arid" => $ar_id, "check" => false)); die(); } } //function to view assignment related questions and answers function get_assign_questions_by_id($assign_id) { global $mysqli; global $dbpref; $table = $dbpref . 'assignment_questions'; $assign_id = trim($mysqli->real_escape_string($assign_id)); $qry = $mysqli->query("SELECT * FROM `" . $table . "` WHERE `assign_id`=" . $assign_id); if (isset($qry->num_rows)) { return $qry; } } //this function is used to create the output of the played quiz questions.. public function create_output($assign_id, $mem_id, $ar_id, $type = "assign") { global $mysqli; global $dbpref; $table1 = $dbpref . "submit_assignment"; $table = $dbpref . "stud_assignment"; $sql = "SELECT * FROM `" . $table . "` WHERE `assign_id`=$assign_id AND `member_id`=$mem_id AND `id`=$ar_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']; $assign_data = self::get_assign_by_id($assign_id); $cert_button = ""; if ($assign_data && isset($assign_data['show_cert']) && (int)$assign_data['show_cert'] === 1 && $this->course_ob->isResultPublished($assign_data['id'], $mem_id, $type)) { $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="' . $type . '"> <input type="hidden" name="cfcourse_cert_exam_id" value="' . cf_enc($assign_data['id']) . '"> <input type="hidden" name="cfcourse_cert_res_id" value="' . cf_enc($ar_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['checked'] == 1) { $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> ' . $cert_button . ' </div> </div> '; $result_data .= self::create_output_buffer($assign_id, $mem_id); } else { $result_data = false; } return $result_data; } //else part now over } //function create output ends here //only one row public function read_student_assign_result($assign_id, $member_id) { global $mysqli; global $dbpref; $table_student_assign = $dbpref . "stud_assignment"; $cond = ""; if ($assign_id) { $assign_id = $mysqli->real_escape_string($assign_id); $cond = " where `assign_id`=" . $assign_id . " and `member_id`=" . $member_id . " limit 1"; } $qry = $mysqli->query("SELECT * FROM `" . $table_student_assign . "`" . $cond); return $qry; } //Will give all the rows of student id and assignment public function read_student_assign_result_all($assign_id, $member_id) { global $mysqli; global $dbpref; $student_assign = $dbpref . "stud_assignment"; $assign_response = $dbpref . "submit_assignment"; $cond = ""; $make_sql = "SELECT cfsr.* FROM `" . $student_assign . "` cfsa LEFT JOIN `" . $assign_response . "` cfsr ON cfsa.`id`=cfsr.`response_id` WHERE cfsa.`assign_id`=$assign_id AND cfsa.`member_id`=$member_id"; $qry = $mysqli->query($make_sql); return $qry; } //this function is used in view assign response area for admin to view all the students who played assign.. public function read_student_assign_response($assign_id) { global $mysqli; global $dbpref; $table_student_assign = $dbpref . "stud_assignment"; $table_member = $dbpref . "quick_member"; $cond = ""; if ($assign_id) { $assign_id = $mysqli->real_escape_string($assign_id); $cond = " where `assign_id`=" . $assign_id; } $make_sql = "SELECT DISTINCT sq.`member_id`,sq.`assign_id`,sq.`assign_title`,sq.`assign_desc`, sq.`submitted_on`,tm.`name`,tm.`email` FROM `" . $table_student_assign . "` AS `sq` INNER JOIN `" . $table_member . "` AS `tm` ON sq.`member_id`=tm.`id` " . $cond; //echo $make_sql; $qry = $mysqli->query($make_sql); return $qry; } //this function is to read all question for that perticular member.. public function read_student_assign_all_questions($assign_id, $member_id) { global $mysqli; global $dbpref; $student_assign = $dbpref . "stud_assignment"; $assign_response = $dbpref . "submit_assignment"; $cond = ""; if ($assign_id) { $assign_id = $mysqli->real_escape_string($assign_id); $cond = " WHERE cfsa.`assign_id`=$assign_id AND cfsa.`member_id`=$member_id"; } $make_sql = "SELECT * FROM `" . $student_assign . "` cfsa INNER JOIN `" . $assign_response . "` cfsr ON cfsa.`id`=cfsr.`response_id` " . $cond; //echo $make_sql; $qry = $mysqli->query($make_sql); return $qry; } //to delete a student assignment response from the admin side.. function delete_a_stud_response($member_id, $assign_id) { global $mysqli; global $dbpref; $table = $dbpref . 'stud_assignment'; $member_id = $mysqli->real_escape_string($member_id); $assign_id = $mysqli->real_escape_string($assign_id); $result = $mysqli->query("delete from `" . $table . "` where `member_id`=" . $member_id . " and `assign_id`=" . $assign_id . ";"); return $result; } //this function is used to create the output of compare result of student answers with the admins answers function create_output_buffer($assign_id, $mem_id) { $assignment_ob = $this->loader->load("assignment_control"); $qry2 = self::read_student_assign_result_all($assign_id, $mem_id); ob_start(); if (!is_object($qry2)) { if ($qry2 == 0) { echo '<div class="input-group"> <h4 class="text-center" style="opacity:0.8;">No Questions Available</h4> </div>'; } } elseif ($qry2->num_rows > 0) { $counter = 0; echo '<div><br><center> <h5 ">Compare your answers with teacher\'s answers </h5></center>'; while ($r = $qry2->fetch_object()) { $question = $assignment_ob->replaceBetweenString($r->questions, "{{code}}", "{{/code}}"); $st_answers = $assignment_ob->replaceBetweenString($r->answers_student, "{{code}}", "{{/code}}"); if (empty($st_answers)) { if (!stristr($st_answers, "Oops! You have not written this answer.")) { $st_answers = "<div class='text-danger cf-course-label-6'>Oops! You have not written this answer.</div>"; } else { $st_answers = "<div class='text-danger cf-course-label-6'>Sorry! You have not written this answer.</div>"; } } $ad_answers = $assignment_ob->replaceBetweenString($r->answers_admin, "{{code}}", "{{/code}}"); $not = strip_tags($st_answers); if (strlen($not) > 280) { $class = "cf-course-assign-ada-ans-h cf-course-assign-ans-h-91px"; $button = '<a href="javascript:void(0)" class="d-inline-block cf-course-assign-ada-btn ">Read More</a>'; } else { $class = ''; $button = ''; } $not1 = strip_tags($ad_answers); if (strlen($not1) > 280) { $class1 = "cf-course-assign-ada-ans-h cf-course-assign-ans-h-91px"; $button1 = '<a href="javascript:void(0)" class="d-inline-block cf-course-assign-ada-btn ">Read More</a>'; } else { $class1 = ''; $button1 = ''; } $counter++; echo '<div class="card p-2 my-2" > <div class="d-flex pb-0"> <div class="cf-course-first-div"><span class="cf-course-label-5">Q ' . $counter . ': </span> </div> <div class="d-flex justify-content-between cf-course-second-div"> <div style="font-weight:500;width:100%">' . $question . '</div> </div> </div> <div class="card-body p-1" > <div class="d-flex pb-0"> <div class="cf-course-first-div"></div> <div class="cf-course-second-div"> <div><span class="cf-course-label-5">Student Answer:</span></div> <div class="cf-course-read-more-des position-relative "> <div class="' . $class . '" style="font-size:0.9em">' . $st_answers . '</div> ' . $button . ' </div> <div class="mt-2"><span class="cf-course-label-5">Admin Answer:</span></div> <div class="cf-course-read-more-des position-relative "> <div class="' . $class1 . '" style="font-size:0.9em">' . $ad_answers . '</div> ' . $button1 . ' </div>'; if ($r->file_path != "") { echo "<div class=' mt-1'><a class='btn btn-sm btn-primary' download href=" . $r->file_path . "><i class='fas fa-download'></i> Download Attachment File</a></div>"; } echo '</div> </div> </div> </div>'; } //end of while loops echo "</div>"; } //end of elseif $store_result = ob_get_clean(); return $store_result; } //to control the ajax request public function getAjaxRequest(array $ajax_datas, $assignment_ob) { global $mysqli; global $dbpref; if ($ajax_datas['cfcourse_assign_param'] == "show_result") { $cfcourse_assign_id = cf_enc($mysqli->real_escape_string($_POST['cfassign_id']), "decrypt"); $content_options = self::get_assign_by_id($cfcourse_assign_id); $cfassign_ques_counter = $mysqli->real_escape_string($_POST['cfassign_ques_counter']); $cfmember_id = cf_enc($mysqli->real_escape_string($_POST['cfmember_id']), "decrypt"); $cfcourse_id = cf_enc($mysqli->real_escape_string($_POST['cfcourse_id']), "decrypt"); $s_id = cf_enc($mysqli->real_escape_string($_POST['cfquiz_s_id']), "decrypt"); $submitted_date = $mysqli->real_escape_string($_POST['date']); $result_out_date = $mysqli->real_escape_string($_POST['result_out_date']); $cfassign_title = $mysqli->real_escape_string($_POST['cfassign_title']); $cfassign_desc = $mysqli->real_escape_string($_POST['cfassign_desc']); $file_upload = $mysqli->real_escape_string($_POST['fl_up']); $test_type = $mysqli->real_escape_string($_POST['test_type']); $astest = $test_type == "assign" ? "Assignment" : "Test"; $time_spend = $mysqli->real_escape_string($_POST['time_spend']); $quiz_ob = $this->loader->load("quiz_stud_control"); $mem_data = $quiz_ob->checkIfIsAdmin($cfmember_id); $mid = $mem_data['mid']; $name = $mem_data['name']; $email = $mem_data['email']; $is_ad = $mem_data['is_ad']; $uploadOk = 1; $response = array('status' => 0, 'message' => '' . $astest . ' Submission Failed, Please try again'); $errMsg = ''; $valid = 1; $table = $dbpref . 'stud_assignment'; $qry2 = self::read_student_assign_result($cfcourse_assign_id, $mid); $question_assign = self::read_assign_question($cfcourse_assign_id); //if qry2 will give empty then only need to upload and insert .. ortherwise do nothing .. if ($qry2->num_rows == 0) { //Uploading file into the folder.. if ($test_type == "assign") { $target_dir = plugin_dir_path(dirname(__FILE__)) . 'assets/assignment/'; $target_dir_url = plugin_dir_url(dirname(__FILE__)) . 'assets/assignment/'; //for storing in db table } else { $target_dir = plugin_dir_path(dirname(__FILE__)) . 'assets/test/'; $target_dir_url = plugin_dir_url(dirname(__FILE__)) . 'assets/test/'; //for storing in db table } $r3 = self::get_assign_by_id($cfcourse_assign_id); //from content option table.. $insert_date = $submitted_date; if ($time_spend == "no-limit") { $time_spent = "No Time Limit"; } else { $time_spent = $this->course_ob->getTime($time_spend); } $attempt_question = 0; for ($i = 0; $i < $cfassign_ques_counter; $i++) { $ans_student = $mysqli->real_escape_string(trim($_POST['ans@' . $i])); if (!empty($ans_student)) { $attempt_question++; } } $un_attempt_question = $cfassign_ques_counter - $attempt_question; $attempt = json_encode(array("answerd" => $attempt_question, "unanswerd" => $un_attempt_question)); $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) { $reutn_iner = -1; } else { $sql = "INSERT INTO `" . $table . "`( `assign_id`, `type`, `member_id`, `course_id`,`name`,`email`,`is_admin`, `assign_title`, `assign_desc`, `submitted_on`,`no_of_questions`,`time_spent`,`attempt_answer`, `result_out_date`) VALUES ('" . $cfcourse_assign_id . "','" . $test_type . "','" . $mid . "',$cfcourse_id,'" . $name . "','" . $email . "',$is_ad,'" . $cfassign_title . "', '" . $cfassign_desc . "','" . $insert_date . "',$cfassign_ques_counter,'" . $time_spent . "','" . $attempt . "','" . $result_out_date . "')"; $reutn_iner = $mysqli->query($sql) ? 1 : -1; } if ($reutn_iner) { $last_id = $mysqli->insert_id; for ($i = 0; $i < $cfassign_ques_counter; $i++) { //Inserting a row into table $que_id = $mysqli->real_escape_string($_POST['que_id@' . $i]); if ($que_id == $question_assign[$i]['id']) { if ($file_upload == "yes") { $uploadOk = 1; //to check if file is suitable to upload $path = $_FILES["files@" . $i]["name"]; if ($path != "") { $ext = pathinfo($path, PATHINFO_EXTENSION); $timeee = date("d_m_Y_H_i_sa", strtotime($submitted_date)); $target_file = $target_dir . "__" . $name . "_m_" . $mid . "_" . $timeee . "_" . $i . "." . $ext; $target_file_url = $target_dir_url . "__" . $name . "_m_" . $mid . "_" . $timeee . "_" . $i . "." . $ext; //for storing in db table } else { $target_file = ""; $target_file_url = ""; } if ($uploadOk == 1) //if all checks(file size and extension) are passed then only try to upload the file .. { if (move_uploaded_file($_FILES["files@" . $i]["tmp_name"], $target_file)) { } else { $valid = 0; $errMsg .= "Sorry, there was an error uploading your file."; $response['message'] = $errMsg; } } } else { $target_file = ""; $target_file_url = ""; } $ans_student = $mysqli->real_escape_string($_POST['ans@' . $i]); $answer_admin = $mysqli->real_escape_string($question_assign[$i]['answers']); $question = $mysqli->real_escape_string($question_assign[$i]['questions']); $target_file2 = $target_file_url; $table2 = $dbpref . "submit_assignment"; $total_count = getTotalCount($table2); if($_SESSION['user_plan_type' . $site_token_for_dashboard] ==2 && $total_count >= 5) { $reutn_i = -1; } else { $sql1 = "INSERT INTO `" . $table2 . "` (`response_id`, `type`, `question_id`, `questions`, `answers_student`, `answers_admin`, `file_path`) VALUES ($last_id,'" . $test_type . "','" . $que_id . "','" . $question . "','" . $ans_student . "','" . $answer_admin . "','" . $target_file2 . "')"; $reutn_i = $mysqli->query($sql1) ? 1 : -1; } } } //end of big for loop } $a_id = cf_enc($cfcourse_assign_id, "encrypt"); $ar_id = cf_enc($last_id, "encrypt"); $c_id = cf_enc($cfcourse_id, "encrypt"); $m_id = cf_enc($mid, "encrypt"); $response['status'] = 1; $response['message'] = $astest . "submitted successfully"; $cert_button = ""; if ($r3 && isset($r3['show_cert']) && (int)$r3['show_cert'] === 1) { $temp_course_ob = $this->loader->load("course_control"); if ($temp_course_ob->isResultPublished($cfcourse_assign_id, $mid, $test_type)) { $cert_button = ' <form action="" method="POST" style="display: inline;"> <input type="hidden" name="cfcourse_cert_exam_type" value="' . $test_type . '"> <input type="hidden" name="cfcourse_cert_exam_id" value="' . $a_id . '"> <input type="hidden" name="cfcourse_cert_res_id" value="' . $ar_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 cf-course-as-Thanks border mt-5 pt-5 text-center"> <h5>Thanks for submitting ' . $astest . '!</h5> <div class="pb-5 pt-2"> <button type="submit" data-mid="' . $m_id . '" data-arid="' . $ar_id . '" data-date="' . $result_out_date . '" data-aid="' . $a_id . '" data-cid="' . $c_id . '" class="btn btn-success btn-sm cf-course-view-assign-result"> View Result </button> </div> <div class="pb-5 pt-2"> ' . $cert_button . ' </div> </div>'; if ($reutn_i) { $response['data'] = $html; $response["op_id"] = $cfcourse_assign_id; echo json_encode($response); if (get_option('reply_assign_test_email') && get_option('reply_assign_test_email') == 1) { self::sendAssinTestEmail($a_id, $c_id, $name, $cfassign_title, $submitted_date, $test_type); } $quiz_ob->addProgress($mid, $cfcourse_assign_id, $cfcourse_id, $s_id); die(); } else { $response['status'] = 0; $response['message'] = "Did you try to hack us?"; echo json_encode($response); die(); } } //end of big if - qry2 will give empty then only need to insert else { $response['status'] = 2; $response['message'] = "You previously already submitted " . $astest . "!!"; echo json_encode($response); die(); } } //if ends of cfcourse_assign_param==show_result ends here .. if ($ajax_datas['cfcourse_assign_param'] == "view_assignment_result") { $test_type = $mysqli->real_escape_string($ajax_datas['type']); $astest = $test_type == "assign" ? "Assignment" : "Test"; $assign_id = cf_enc($mysqli->real_escape_string($ajax_datas['a_id']), "decrypt"); $add_times_ser = $mysqli->real_escape_string($ajax_datas['date']); $no_of_days = $mysqli->real_escape_string($ajax_datas['days']); $ar_id = cf_enc($mysqli->real_escape_string($ajax_datas['ar_id']), "decrypt"); $m_id = cf_enc($mysqli->real_escape_string($ajax_datas['m_id']), "decrypt"); $quiz_ob = $this->loader->load("quiz_stud_control"); $mem_data = $quiz_ob->checkIfIsAdmin($m_id); $member_id = $mem_data['mid']; $enable_days = self::getAssignById($assign_id, "delay_result"); $edays = (int)$enable_days['delay_result']; $qry = self::read_student_assign_result($assign_id, $member_id); $create_output_buffer = self::create_output($assign_id, $member_id, $ar_id, $test_type); while ($r = $qry->fetch_object()) { $result_out_date = $r->result_out_date; } //while loop ends if ($no_of_days > 0 && $edays === 1) // this one is correct .. if($no_of_days>0) { echo json_encode(array("no_of_days" => $no_of_days, "checked" => true, "status" => "locked", "date" => $result_out_date, "checked" => true,)); die(); } else { if ($create_output_buffer) { echo json_encode(array("no_of_days" => $no_of_days, "status" => "unlocked", "checked" => true, "output" => $create_output_buffer)); } else { echo json_encode(array("no_of_days" => $no_of_days, "status" => "locked", "checked" => false)); } die(); } } } //function getAjaxRequest ends here function sendAssinTestEmail($a_id, $c_id, $name, $title, $time, $type) { if ($type == "assign") { $astest = "Assignment"; $newurl = get_option("install_url") . "?page=cfcourse_assignment&cfcourse_id=" . $c_id . "&cfcontent_id=" . $a_id; } else { $astest = "Test"; $newurl = get_option("install_url") . "?page=cfcourse_test&cfcourse_id=" . $c_id . "&cfcontent_id=" . $a_id; } $email_body = "<p>Hello,</p>"; $com_email = get_option("communication_email"); $subject = "(CourseFunnels) $astest Notification"; $email_body .= "<p>I hope you’re having a great week. <strong>" . $name . "</strong> has submitted the " . $astest . " <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 read_assign_question($assign_id) { global $mysqli; global $dbpref; $assign_id = $mysqli->real_escape_string($assign_id); $table = $dbpref . 'assignment_questions'; $sql = "SELECT * FROM `" . $table . "` WHERE `assign_id`=" . $assign_id; $row = $mysqli->query($sql); $data = []; if ($row->num_rows > 0) { while ($r = $row->fetch_assoc()) { $data[] = $r; } } return $data; } } //class ends }//if check class_exists ends