static function cleanup($course_id, $student_id) { global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM " . NAMASTE_STUDENT_COURSES . " \n\t\t \tWHERE course_id = %d AND user_id=%d", $course_id, $student_id)); $wpdb->query($wpdb->prepare("DELETE FROM " . NAMASTE_STUDENT_LESSONS . " WHERE student_id= %d AND lesson_id IN (SELECT ID FROM {$wpdb->posts} tP JOIN {$wpdb->postmeta} tM ON tM.post_id = tP.ID AND tM.meta_key = 'namaste_course' AND tM.meta_value = %d WHERE post_type = 'namaste_lesson');", $student_id, $course_id)); // delete solutions $wpdb->query($wpdb->prepare("DELETE FROM " . NAMASTE_STUDENT_HOMEWORKS . " WHERE student_id=%d\n\t\t\tAND homework_id IN (SELECT id FROM " . NAMASTE_HOMEWORKS . " WHERE course_id=%d)", $student_id, $course_id)); // cleanup exams data? $use_exams = get_option('namaste_use_exams'); if ($use_exams and get_option('namaste_cleanup_exams') == 'yes') { // select all exam IDs of related lessons $_lesson = new NamasteLMSLessonModel(); $lessons = $_lesson->select($course_id); $exam_ids = array(0); foreach ($lessons as $lesson) { $exam_id = get_post_meta($lesson->ID, 'namaste_required_exam', true); if (!empty($exam_id)) { $exam_ids[] = $exam_id; } } // now delete if ($use_exams == 'watu') { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}watu_takings WHERE user_id=%d AND exam_id IN (" . implode(',', $exam_ids) . ")", $student_id)); } if ($use_exams == 'watupro') { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}watupro_taken_exams WHERE user_id=%d AND exam_id IN (" . implode(',', $exam_ids) . ")", $student_id)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}watupro_student_answers WHERE user_id=%d AND exam_id IN (" . implode(',', $exam_ids) . ")", $student_id)); } } }
static function todo($lesson_id, $student_id) { global $wpdb; $todo_homeworks = $todo_exam = $todo_admin_approval = NULL; // for homeworks automatically detect if there is a post that contains [namaste-assignments lesson_id="X"] // If yes, generate proper submit link instead of going into the admin $homework_posts = $wpdb->get_results("SELECT ID, post_content FROM {$wpdb->posts}\n\t\t\tWHERE post_status = 'publish' AND post_date < NOW()\n\t\t\tAND post_content LIKE '%[namaste-assignments%' ORDER BY ID DESC"); $post_found = null; foreach ($homework_posts as $post) { if (stristr($post->post_content, '[namaste-assignments lesson_id="' . $lesson_id . '"]') or stristr($post->post_content, '[namaste-assignments lesson_id=' . $lesson_id . ']')) { $post_found = $post->ID; break; } } // todo homeworks $required_homeworks = get_post_meta($lesson_id, 'namaste_required_homeworks', true); if (!is_array($required_homeworks)) { $required_homeworks = array(); } if (!empty($required_homeworks)) { // select all completed homeworks of this student and see if all required are satisfied $completed_homeworks = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT(homework_id) FROM " . NAMASTE_STUDENT_HOMEWORKS . " WHERE student_id=%d AND status='approved'", $student_id)); $ids = array(0); foreach ($completed_homeworks as $hw) { $ids[] = $hw->homework_id; } $todo_homeworks = array(); foreach ($required_homeworks as $required_id) { if (!empty($required_id) and !in_array($required_id, $ids)) { $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . " WHERE id=%d", $required_id)); if (empty($homework->id)) { continue; } // define the submit link if ($post_found) { $permalink = get_permalink($post_found); $params = array('id' => $homework->id, 'submit_solution' => 1); $target_url = add_query_arg($params, $permalink); $homework->submit_link = $target_url; } else { $homework->submit_link = admin_url("admin.php?page=namaste_submit_solution&id=" . $homework->id); } $todo_homeworks[] = $homework; } } } // todo exam $use_exams = get_option('namaste_use_exams'); $todo_exam = NamasteLMSLessonModel::todo_exam($lesson_id, $student_id, 'id'); if (!empty($todo_exam)) { if ($use_exams == 'watu') { $todo_exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}watu_master WHERE ID=%d", $todo_exam)); $codesearch = "[WATU " . $todo_exam->ID . "]"; } if ($use_exams == 'watupro') { $todo_exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}watupro_master WHERE ID=%d", $todo_exam)); $codesearch = "[WATUPRO " . $todo_exam->ID . "]"; } // find the post to match it to the exam $post = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE post_content LIKE '%{$codesearch}%' \n\t\t\t\tAND post_status='publish' AND post_title!='' ORDER BY post_date DESC"); $todo_exam->post_link = get_permalink(@$post->ID); } // admin approval? $todo_admin_approval = false; $lesson_completion = get_post_meta($lesson_id, 'namaste_completion', true); if (is_array($lesson_completion) and in_array('admin_approval', $lesson_completion)) { $todo_admin_approval = true; } // namaste-mark button? $todo_mark = false; $lesson = get_post($lesson_id); if (strstr($lesson->post_content, '[namaste-mark')) { $todo_mark = true; } $nothing = false; if (empty($todo_homeworks) and empty($todo_exam) and empty($todo_admin_approval) and empty($todo_mark)) { $nothing = true; } // return todo return array("todo_homeworks" => $todo_homeworks, "todo_exam" => $todo_exam, "todo_admin_approval" => $todo_admin_approval, "todo_mark" => $todo_mark, "todo_nothing" => $nothing); }
function required_lessons($course_id, $student_id) { global $wpdb; $required_lessons_ids = get_post_meta($course_id, 'namaste_required_lessons', true); if (!is_array($required_lessons_ids)) { return array(); } $required_lessons = $wpdb->get_results("SELECT * FROM {$wpdb->posts} \n\t\t\tWHERE ID IN (" . implode(",", $required_lessons_ids) . ") ORDER BY ID"); foreach ($required_lessons as $cnt => $lesson) { $required_lessons[$cnt]->namaste_completed = 0; if (NamasteLMSLessonModel::is_completed($lesson->ID, $student_id)) { $required_lessons[$cnt]->namaste_completed = 1; } } return $required_lessons; }
static function full_select($id) { global $wpdb; $_course = new NamasteLMSCourseModel(); $_lesson = new NamasteLMSLessonModel(); // select this homework and lesson $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . "\n\t\t\tWHERE id=%d", $id)); // select course $course = $_course->select($homework->course_id); // select lesson $lesson = $_lesson->select($course->ID, 'single', $homework->lesson_id); return array($homework, $course, $lesson); }
static function mark() { global $wpdb, $post, $user_ID; if (!is_user_logged_in()) { return ""; } // is the lesson in progress? $in_progress = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . NAMASTE_STUDENT_LESSONS . " \n\t\t\tWHERE lesson_id=%d AND student_id=%d AND status!=1", $post->ID, $user_ID)); if (!$in_progress) { return ''; } // ready for completion? if (NamasteLMSLessonModel::is_ready($post->ID, $user_ID, false, true)) { // display button or mark as completed if (!empty($_POST['mark'])) { NamasteLMSLessonModel::complete($post->ID, $user_ID); return __('Lesson completed!', 'namaste'); } else { return '<form method="post" action=""> <p><input type="submit" name="mark" value="' . __('Mark as completed', 'namaste') . '"></p> </form>'; } } }
function namaste_ajax() { global $wpdb, $user_ID; $type = empty($_POST['type']) ? $_GET['type'] : $_POST['type']; switch ($type) { case 'lessons_for_course': $_lesson = new NamasteLMSLessonModel(); echo $_lesson->select($_POST['course_id'], 'json', null, 'ID'); break; // load notes for student homework // load notes for student homework case 'load_notes': // unless I am manager I can see other user's notes if ($user_ID != $_GET['student_id'] and !current_user_can('namaste_manage')) { wp_die('You are not allowed to see these notes.', 'namaste'); } // select notes $notes = $wpdb->get_results($wpdb->prepare("SELECT tN.*, tU.user_login as username\n\t\t\t FROM " . NAMASTE_HOMEWORK_NOTES . " tN JOIN {$wpdb->users} tU ON tU.ID = tN.teacher_id\n\t\t\t\tWHERE homework_id=%d AND student_id=%d ORDER BY tN.id DESC", $_GET['homework_id'], $_GET['student_id'])); // select homework $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . " WHERE id=%d", $_GET['homework_id'])); if (@file_exists(get_stylesheet_directory() . '/namaste/homework-notes.php')) { require get_stylesheet_directory() . '/namaste/homework-notes.php'; } else { require NAMASTE_PATH . "/views/homework-notes.php"; } break; // show lesson progress // show lesson progress case 'lesson_progress': // if i am not manager I can see only my own todo if (!current_user_can('namaste_manage') and $user_ID != $_GET['student_id']) { die(__("You are not allowed to view this", 'namaste')); } // select lesson and student $lesson = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID=%d", $_GET['lesson_id'])); $student = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID=%d", $_GET['student_id'])); $todo = NamasteLMSLessonModel::todo($_GET['lesson_id'], $_GET['student_id']); if (@file_exists(get_stylesheet_directory() . '/namaste/lesson-todo.php')) { require get_stylesheet_directory() . '/namaste/lesson-todo.php'; } else { require NAMASTE_PATH . "/views/lesson-todo.php"; } break; // display payment screen for a course // display payment screen for a course case 'course_payment': // select course $course = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID=%d", $_GET['course_id'])); $fee = get_post_meta($course->ID, 'namaste_fee', true); $fee = apply_filters('namaste-coupon-applied', $fee); $currency = get_option('namaste_currency'); $accept_other_payment_methods = get_option('namaste_accept_other_payment_methods'); $accept_paypal = get_option('namaste_accept_paypal'); $paypal_id = get_option('namaste_paypal_id'); if ($accept_other_payment_methods) { $other_payment_methods = stripslashes(get_option('namaste_other_payment_methods')); $other_payment_methods = str_replace('{{course-id}}', $course->ID, $other_payment_methods); $other_payment_methods = str_replace('{{course-name}}', $course->post_title, $other_payment_methods); $other_payment_methods = str_replace('{{user-id}}', $_GET['student_id'], $other_payment_methods); $other_payment_methods = str_replace('{{amount}}', $fee, $other_payment_methods); $other_payment_methods = str_replace('{{item-type}}', 'course', $other_payment_methods); $other_payment_methods = do_shortcode($other_payment_methods); } // return URL $paypal_return = get_option('namaste_paypal_return'); if (empty($paypal_return)) { $paypal_return = get_permalink($course->ID); } if (!strstr($paypal_return, 'http')) { $paypal_return = 'http://' . $paypal_return; } if (@file_exists(get_stylesheet_directory() . '/namaste/course-pay.php')) { require get_stylesheet_directory() . '/namaste/course-pay.php'; } else { require NAMASTE_PATH . "/views/course-pay.php"; } break; // set student's grade for a course or lesson // set student's grade for a course or lesson case 'set_grade': if (!current_user_can('namaste_manage')) { die(__('You are not allowed to grade', 'namaste')); } if ($_POST['grade_what'] == 'course') { $table = NAMASTE_STUDENT_COURSES; $field = 'course_id'; $student_field = 'user_id'; do_action('namaste_graded_course', $_POST['student_id'], $_POST['item_id'], $_POST['grade']); } else { $table = NAMASTE_STUDENT_LESSONS; $field = 'lesson_id'; $student_field = 'student_id'; do_action('namaste_graded_lesson', $_POST['student_id'], $_POST['item_id'], $_POST['grade']); } // now update the grade $wpdb->query($wpdb->prepare("UPDATE {$table} SET grade=%s WHERE {$field}=%d AND {$student_field}=%d", $_POST['grade'], $_POST['item_id'], $_POST['student_id'])); break; } exit; }
static function install($update = false) { global $wpdb; $wpdb->show_errors(); $old_version = get_option('namaste_version'); update_option('namaste_version', "1.34"); if (!$update) { self::init(); } // enrollments to courses if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_COURSES . "'") != NAMASTE_STUDENT_COURSES) { $sql = "CREATE TABLE `" . NAMASTE_STUDENT_COURSES . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`status` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t\t`enrollment_date` DATE NOT NULL DEFAULT '2000-01-01',\t\t\t\n\t\t\t\t\t`completion_date` DATE NOT NULL DEFAULT '2000-01-01',\n\t\t\t\t\t`comments` TEXT NOT NULL\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // assignments - let's not use custom post type for this if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_HOMEWORKS . "'") != NAMASTE_HOMEWORKS) { $sql = "CREATE TABLE `" . NAMASTE_HOMEWORKS . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`lesson_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`title` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t\t`description` TEXT NOT NULL,\n\t\t\t\t\t`accept_files` TINYINT NOT NULL DEFAULT 0 /* zip only */\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // student - assignments relation if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_HOMEWORKS . "'") != NAMASTE_STUDENT_HOMEWORKS) { $sql = "CREATE TABLE `" . NAMASTE_STUDENT_HOMEWORKS . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`homework_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`status` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t\t`date_submitted` DATE NOT NULL DEFAULT '2000-01-01',\n\t\t\t\t\t`content` TEXT NOT NULL,\n\t\t\t\t\t`file` VARCHAR(255) NOT NULL DEFAULT ''\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // assignment notes (usually used as feedback from the teacher to the student. Student can't reply) if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_HOMEWORK_NOTES . "'") != NAMASTE_HOMEWORK_NOTES) { $sql = "CREATE TABLE `" . NAMASTE_HOMEWORK_NOTES . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`homework_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`teacher_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`note` TEXT NOT NULL,\n\t\t\t\t\t`datetime` DATETIME NOT NULL DEFAULT '2000-01-01'\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // student to lessons relation - only save record if student has completed a lesson if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_LESSONS . "'") != NAMASTE_STUDENT_LESSONS) { $sql = "CREATE TABLE `" . NAMASTE_STUDENT_LESSONS . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t`lesson_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`status` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t\t`completion_date` TEXT NOT NULL\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_CERTIFICATES . "'") != NAMASTE_CERTIFICATES) { $sql = "CREATE TABLE `" . NAMASTE_CERTIFICATES . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t `course_ids` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t `title` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t `content` TEXT NOT NULL\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_STUDENT_CERTIFICATES . "'") != NAMASTE_STUDENT_CERTIFICATES) { $sql = "CREATE TABLE `" . NAMASTE_STUDENT_CERTIFICATES . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t `certificate_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `student_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `date` DATE NOT NULL DEFAULT '2000-01-01'\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // payment records if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_PAYMENTS . "'") != NAMASTE_PAYMENTS) { $sql = "CREATE TABLE `" . NAMASTE_PAYMENTS . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t `course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `date` DATE NOT NULL DEFAULT '2001-01-01',\n\t\t\t\t `amount` DECIMAL(8,2),\n\t\t\t\t `status` VARCHAR(100) NOT NULL DEFAULT 'failed',\n\t\t\t\t `paycode` VARCHAR(100) NOT NULL DEFAULT '',\n\t\t\t\t `paytype` VARCHAR(100) NOT NULL DEFAULT 'paypal'\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // tracks the visits on a give course or lesson // 1 record per user/date if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_VISITS . "'") != NAMASTE_VISITS) { $sql = "CREATE TABLE `" . NAMASTE_VISITS . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t `course_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `lesson_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `date` DATE NOT NULL DEFAULT '2001-01-01',\n\t\t\t\t `visits` INT UNSIGNED NOT NULL DEFAULT 0\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // history of various actions, for example points awarded and spent if ($wpdb->get_var("SHOW TABLES LIKE '" . NAMASTE_HISTORY . "'") != NAMASTE_HISTORY) { $sql = "CREATE TABLE `" . NAMASTE_HISTORY . "` (\n\t\t\t\t `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t `user_id` INT UNSIGNED NOT NULL DEFAULT 0,\n\t\t\t\t `date` DATE NOT NULL DEFAULT '2001-01-01',\n\t\t\t\t `datetime` DATETIME,\n\t\t\t\t `action` VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\t\t `value` VARCHAR(255) NOT NULL DEFAULT '', /* some textual value if required */\n\t\t\t\t `num_value` INT UNSIGNED NOT NULL DEFAULT 0 /* some numeric value, for example points */\n\t\t\t\t) DEFAULT CHARSET=utf8;"; $wpdb->query($sql); } // add extra fields in new versions namaste_add_db_fields(array(array("name" => "grade", "type" => "VARCHAR(100) NOT NULL DEFAULT ''"), array("name" => "fileblob", "type" => "LONGBLOB")), NAMASTE_STUDENT_HOMEWORKS); namaste_add_db_fields(array(array("name" => "grade", "type" => "VARCHAR(100) NOT NULL DEFAULT ''"), array("name" => "enrollment_time", "type" => "DATETIME"), array("name" => "completion_time", "type" => "DATETIME")), NAMASTE_STUDENT_COURSES); namaste_add_db_fields(array(array("name" => "grade", "type" => "VARCHAR(100) NOT NULL DEFAULT ''"), array("name" => "start_time", "type" => "DATETIME"), array("name" => "completion_time", "type" => "DATETIME")), NAMASTE_STUDENT_LESSONS); namaste_add_db_fields(array(array("name" => "award_points", "type" => "INT UNSIGNED NOT NULL DEFAULT 0"), array("name" => "editor_id", "type" => "INT UNSIGNED NOT NULL DEFAULT 0")), NAMASTE_HOMEWORKS); namaste_add_db_fields(array(array("name" => "editor_id", "type" => "INT UNSIGNED NOT NULL DEFAULT 0")), NAMASTE_CERTIFICATES); namaste_add_db_fields(array(array("name" => "for_item_type", "type" => "VARCHAR(100) NOT NULL DEFAULT '' "), array("name" => "for_item_id", "type" => "INT UNSIGNED NOT NULL DEFAULT 0")), NAMASTE_HISTORY); // add student role if not exists $res = add_role('student', 'Student', array('read' => true, 'namaste' => true)); if (!$res) { // role already exists, check the capability $role = get_role('student'); if (!$role->has_cap('namaste')) { $role->add_cap('namaste'); } } // add manage cap to the admin / superadmin by default $role = get_role('administrator'); if (!$role->has_cap('namaste_manage')) { $role->add_cap('namaste_manage'); } // update fileblob if ($old_version < 1.27) { $wpdb->query("ALTER TABLE " . NAMASTE_STUDENT_HOMEWORKS . " CHANGE fileblob fileblob LONGBLOB"); } /* This was needed only for a while but now is generated "unexpected output" during activation if($old_version < 1.29) { // drop student-certificate uniqueness, no longer used $sql = "ALTER TABLE ".NAMASTE_STUDENT_CERTIFICATES." DROP INDEX certificate_id"; $wpdb->query($sql); }*/ // fush rewrite rules NamasteLMSCourseModel::register_course_type(); NamasteLMSLessonModel::register_lesson_type(); flush_rewrite_rules(); // exit; }
} break; } } } $quiz_details = $wpdb->get_row($wpdb->prepare("SELECT name,final_screen, description FROM {$wpdb->prefix}watu_master WHERE ID=%d", $exam_id)); $quiz_details->final_screen = str_replace('%%TOTAL%%', '%%MAX-POINTS%%', $quiz_details->final_screen); $replace_these = array('%%SCORE%%', '%%MAX-POINTS%%', '%%PERCENTAGE%%', '%%GRADE%%', '%%RATING%%', '%%CORRECT%%', '%%WRONG_ANSWERS%%', '%%QUIZ_NAME%%', '%%DESCRIPTION%%', '%%GRADE-TITLE%%', '%%GRADE-DESCRIPTION%%', '%%POINTS%%'); $with_these = array($achieved, $max_points, $percent, $grade, $rating, $num_correct, $num_questions - $num_correct, stripslashes($quiz_details->name), wpautop(stripslashes($quiz_details->description)), $gtitle, $gdescription, $achieved); // insert taking $uid = $user_ID ? $user_ID : 0; $wpdb->query($wpdb->prepare("INSERT INTO " . WATU_TAKINGS . " SET exam_id=%d, user_id=%d, ip=%s, date=CURDATE(),\r\n\t\tpoints=%d, grade_id=%d, result=%s, snapshot=''", $exam_id, $uid, $_SERVER['REMOTE_ADDR'], $achieved, $g_id, $grade)); $taking_id = $wpdb->insert_id; // Show the results $output = str_replace($replace_these, $with_these, wpautop(stripslashes($quiz_details->final_screen))); if (isset($_REQUEST['lesson_id']) && is_numeric($_REQUEST['lesson_id']) && $uid && NamasteLMSLessonModel::is_ready($_REQUEST['lesson_id'], $uid, true)) { $output .= '<script>alert("true");</script>'; } else { $output .= '<script>alert("false");</script>'; } $final_output = apply_filters(WATU_CONTENT_FILTER, $output); echo $final_output; $results_output = '<hr />' . apply_filters(WATU_CONTENT_FILTER, $result); if ($answer_display == 1) { echo $results_output; } $snapshot = $final_output . $results_output; // update snapshot $wpdb->query($wpdb->prepare("UPDATE " . WATU_TAKINGS . " SET snapshot=%s WHERE ID=%d", $snapshot, $taking_id)); // notify admin if (!empty($exam->notify_admin)) {
function watucas_scheck() { $uid = get_current_user_id(); if (isset($_REQUEST['lesson_id']) && is_numeric($_REQUEST['lesson_id']) && $uid && NamasteLMSLessonModel::is_ready($_REQUEST['lesson_id'], $uid, true)) { echo ' <script> jQuery(function ($) { jQuery(\'input[name="mark"]\').each(function(){ jQuery(this).removeAttr("disabled"); }); }); </script>'; } }
function completeness($lesson, $student_id, $homeworks, $solutions) { if ($lesson->lesson_status == 1) { return 100; } $completeness = $completeness_parts = 0; $lesson_completion = get_post_meta($lesson->ID, 'namaste_completion', true); if (!is_array($lesson_completion)) { $lesson_completion = array(); } $required_homeworks = get_post_meta($lesson->ID, 'namaste_required_homeworks', true); if (!is_array($required_homeworks)) { $required_homeworks = array(); } $required_exam = get_post_meta($lesson->ID, 'namaste_required_exam', true); if (in_array('admin_approval', $lesson_completion)) { $completeness_parts += 1; } if (!empty($required_exam)) { $completeness_parts += 1; } if (sizeof($required_homeworks)) { $completeness_parts += 2; } // when there are no requirements at all but the lesson is not completed, return 0 if (!$completeness_parts) { return 0; } // if required exam, let's see whether it's completed if (NamasteLMSLessonModel::todo_exam($lesson->ID, $student_id, 'boolean')) { $completeness += 1; } // if required homeworks, let's see what part of them are completed so we can calculate part of 2 if (sizeof($required_homeworks)) { $num_required = $num_completed = 0; foreach ($homeworks as $homework) { if ($homework->lesson_id == $lesson->ID and in_array($homework->id, $required_homeworks)) { $num_required++; foreach ($solutions as $solution) { if ($solution->homework_id == $homework->id and $solution->status == 'approved') { $num_completed++; break; } } // end foreach solution } // end if match } // end foreach homework if ($num_required) { $homework_completeness = round($num_completed / $num_required * 2, 2); } else { $homework_completeness = 0; } $completeness += $homework_completeness; } // end if sizeof homeworks // now calculate completeness in % $comp_perc = round(100 * ($completeness / $completeness_parts)); return $comp_perc; }
static function manage() { global $wpdb; $_course = new NamasteLMSCourseModel(); $_lesson = new NamasteLMSLessonModel(); // select grades $grades = explode(",", stripslashes(get_option('namaste_grading_system'))); // select courses $courses = $_course->select(); $courses = apply_filters('namaste-homeworks-select-courses', $courses); // if course is selected, select in progress students in the course, // select lessons and homeworks in it too if (!empty($_GET['course_id'])) { do_action('namaste-check-permissions', 'course', $_GET['course_id']); $this_course = $_course->select($_GET['course_id']); $lessons = $_lesson->select($_GET['course_id']); $lids = array(0); foreach ($lessons as $lesson) { $lids[] = $lesson->ID; } $students = $wpdb->get_results($wpdb->prepare("SELECT tU.*, tS.status as namaste_status, tS.grade as course_grade \n\t\t \t\tFROM {$wpdb->users} tU JOIN " . NAMASTE_STUDENT_COURSES . " tS \n\t\t \t\tON tS.user_id = tU.ID AND tS.course_id=%d AND (tS.status='enrolled' OR status='completed')\n\t\t \t\tORDER BY user_nicename", $_GET['course_id'])); $stids = array(0); foreach ($students as $student) { $stids[] = $student->ID; } // select student-lessons and student-homeworks for this course so we can have the grades $student_lessons = $wpdb->get_results("SELECT * FROM " . NAMASTE_STUDENT_LESSONS . "\n\t\t\t\tWHERE lesson_id IN (" . implode(',', $lids) . ") AND student_id IN (" . implode(',', $stids) . ")\n\t\t\t\tORDER BY id"); $student_homeworks = $wpdb->get_results("SELECT tSH.*, tH.lesson_id as lesson_id FROM " . NAMASTE_STUDENT_HOMEWORKS . " tSH\n\t\t\t\tJOIN " . NAMASTE_HOMEWORKS . " tH ON tH.id = tSH.homework_id\n\t\t\t\tWHERE tH.lesson_id IN (" . implode(',', $lids) . ") AND tSH.student_id IN (" . implode(',', $stids) . ") \n\t\t\t\tORDER BY id"); // now match everything together so we have it ready for the table foreach ($students as $cnt => $student) { $lesson_grades = array(); $lesson_ids = array(); foreach ($lessons as $lesson) { foreach ($student_lessons as $student_lesson) { if ($student_lesson->student_id == $student->ID and $student_lesson->lesson_id == $lesson->ID) { // get homework grades $homework_grades = array(); $lesson_ids[] = $lesson->ID; foreach ($student_homeworks as $student_homework) { if ($student_homework->student_id != $student->ID) { continue; } if ($student_homework->lesson_id != $lesson->ID) { continue; } if (empty($student_homework->grade)) { continue; } $homework_grades[] = $student_homework->grade; } // end foreach student_homeworks $lesson_grades[] = array('homework_grades' => $homework_grades, "final_grade" => $student_lesson->grade, 'lesson_id' => $student_lesson->lesson_id); } // end student & lesson match } // end foreach $student_lessons } // end foreach $lesson $students[$cnt]->lesson_grades = $lesson_grades; $students[$cnt]->lesson_ids = $lesson_ids; } // end foreach $student } // end if $_GET[course_id] if (@file_exists(get_stylesheet_directory() . '/namaste/gradebook.html.php')) { require get_stylesheet_directory() . '/namaste/gradebook.html.php'; } else { require NAMASTE_PATH . "/views/gradebook.html.php"; } }
static function change_solution_status($lesson, $student_id = NULL) { global $wpdb, $user_ID; if (!current_user_can('namaste_manage')) { wp_die(__('You are not allowed to do this', 'namaste')); } $solution = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_STUDENT_HOMEWORKS . " WHERE id=%d", $_POST['solution_id'])); if (!$student_id) { $student_id = $solution->student_id; } $homework = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . NAMASTE_HOMEWORKS . " WHERE id=%d", $solution->homework_id)); $multiuser_access = 'all'; $multiuser_access = NamasteLMSMultiUser::check_access('homework_access'); if ($multiuser_access == 'own' and $homework->editor_id != $user_ID) { wp_die(__('You are not allowed to see these solutions', 'namaste')); } $wpdb->query($wpdb->prepare("UPDATE " . NAMASTE_STUDENT_HOMEWORKS . " SET\n\t\t\tstatus=%s WHERE id=%d", $_POST['status'], $_POST['solution_id'])); do_action('namaste_change_solution_status', $student_id, $_POST['solution_id'], $_POST['status']); // insert in history $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_HISTORY . " SET\n\t\t\tuser_id=%d, date=CURDATE(), datetime=NOW(), action='solution_processed', value=%s, num_value=%d", $student_id, sprintf(__('Solution to assignment %s was %s', 'namaste'), $homework->title, $_POST['status']), $_POST['solution_id'])); // award points? if ($_POST['status'] == 'approved' and get_option('namaste_use_points_system')) { if ($homework->award_points) { NamastePoint::award($student_id, $homework->award_points, sprintf(__('Received %d points for completing assignment "%s".', 'namaste'), $homework->award_points, $homework->title, 'homework', $homework->id)); } } // maybe complete the lesson if the status is approved if ($_POST['status'] == 'approved' and NamasteLMSLessonModel::is_ready($lesson->ID, $student_id)) { NamasteLMSLessonModel::complete($lesson->ID, $student_id); } }