safeStringInput($_GET['c'], true)); $post_id = intval($this->safeStringInput($_GET['p'], true)); $subscription_id = intval($this->safeStringInput($_GET['s'], true)); //IF we have active course proceed $course_meta = new CourseMeta($course_id); if($course_meta->getIsCourse()) { $student = $course_meta->getStudentBySubscription($subscription_id); $student_answer = $course_meta->getStudentAssignmentAnswer($student, $post_id); //If we have post request, this means "Send feedback" button was pressed if(isSet($_POST)) { if($_POST['action'] == 'sendFeedback') { $feedback_status = $course_meta->sendFeedback($post_id, $student, $student_answer, $_POST['feedback'], $_POST['grade']); } } //Get some metadata from DB $meta_data = get_post_meta($post_id, '_lepress-student-'.md5($post_id.$student->email), true); $display_name_order = $this->getDisplayNames(); $name = $display_name_order == 1 ? $student->first_name.' '.$student->last_name : $student->last_name.' '.$student->first_name; //Get some posts $posts_query = get_posts(array('meta_query' => array(array('key' => '_is-lepress-assignment', 'value' => 1)), 'p' => $post_id, 'category' => $course_id, 'post_status' => 'publish', 'numberposts' => 1)); $post = $posts_query[0]; /* Display some feedback to user */ $js_redirect = false; if($feedback_status == 200) { //Everything went well $str = str_replace('{name}', ''.$name.'', __('Your feedback to student {name} is sent. Redirecting to the assignment page...', lepress_textdomain)); $this->echoNoticeDiv($str); //Delete comment metadata lepress-read $comment = $this->fetchComment($post_id, $student->email, 'LePressStudent'); delete_comment_meta($comment->comment_ID, 'lepress-read'); update_comment_meta($comment->comment_ID, 'lepress-feedback-given', 1); $js_redirect = true; } elseif($feedback_status == -1) { //User not a teacher on this course $this->echoNoticeDiv(__('You are not teacher on this course, sorry... Cannot allow sending feedback.', lepress_textdomain), true); } elseif($feedback_status == -2) { //Course has been closed $comment = $this->fetchComment($post_id, $student->email, 'LePressStudent'); delete_comment_meta($comment->comment_ID, 'lepress-read'); update_comment_meta($comment->comment_ID, 'lepress-feedback-given', 1); $str = __('Your feedback was not sent, because course of this assignment is set as closed', lepress_textdomain); $this->echoNoticeDiv($str, true); } elseif($feedback_status == -3) { //No changes end feedback, text/grade not sending request $str = __('No changes detected, not sending feeback. Redirecting to the assignment page...', lepress_textdomain); $this->echoNoticeDiv($str, false); $js_redirect = true; } elseif(isSet($feedback_status)) { //General error, something went terribly wrong $str = str_replace('{name}', ''.$name.'', __('Your feedback to student {name} was not sent. Try again...', lepress_textdomain)); $this->echoNoticeDiv($str, true); } $back_url = admin_url().'admin.php?page=lepress-classbook&p='.$post_id.'&c='.$course_id; //Redirect to assignment page with JS code if($js_redirect) { ?>