function xmldb_qtype_numerical_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; // In numerical questions, we are changing the 'match anything' answer // from the empty string to *, to be like short answer questions. if ($result && $oldversion < 2006121500) { $result = set_field_select('question_answers', 'answer', '*', sql_compare_text('answer') . " = '" . sql_empty() . "' AND question IN (SELECT id FROM {$CFG->prefix}question WHERE qtype = '" . NUMERICAL . "')"); } return $result; }
function scorm_simple_play($scorm, $user) { $result = false; if ($scorm->updatefreq == UPDATE_EVERYTIME) { scorm_parse($scorm); } $scoes = get_records_select('scorm_scoes', 'scorm=' . $scorm->id . ' AND launch<>\'' . sql_empty() . '\''); if ($scoes) { if ($scorm->skipview >= 1) { $sco = current($scoes); if (scorm_get_tracks($sco->id, $user->id) === false) { header('Location: player.php?a=' . $scorm->id . '&scoid=' . $sco->id); $result = true; } else { if ($scorm->skipview == 2) { header('Location: player.php?a=' . $scorm->id . '&scoid=' . $sco->id); $result = true; } } } } return $result; }
/** * Given a scorm id return all the grades of that activity * * @param int $scormid Scorm instance id * @return mixed */ function scorm_grades($scormid) { global $CFG; if (!($scorm = get_record('scorm', 'id', $scormid))) { return NULL; } if ($scorm->grademethod % 10 == 0) { // GRADESCOES if (!($return->maxgrade = count_records_select('scorm_scoes', "scorm='{$scormid}' AND launch<>'" . sql_empty() . "'"))) { return NULL; } } else { $return->maxgrade = $scorm->maxgrade; } $return->grades = NULL; if ($scousers = get_records_select('scorm_scoes_track', "scormid='{$scormid}' GROUP BY userid", "", "userid,null")) { require_once 'locallib.php'; foreach ($scousers as $scouser) { $return->grades[$scouser->userid] = scorm_grade_user($scorm, $scouser->userid); } } return $return; }
/** * Update/create grade item for given scorm * * @param object $scorm object with extra cmidnumber * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook * @return object grade_item */ function scorm_grade_item_update($scorm, $grades = NULL) { global $CFG; if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once $CFG->libdir . '/gradelib.php'; } $params = array('itemname' => $scorm->name); if (isset($scorm->cmidnumber)) { $params['idnumber'] = $scorm->cmidnumber; } if ($scorm->grademethod % 10 == 0) { // GRADESCOES if ($maxgrade = count_records_select('scorm_scoes', "scorm='{$scorm->id}' AND launch<>'" . sql_empty() . "'")) { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $maxgrade; $params['grademin'] = 0; } else { $params['gradetype'] = GRADE_TYPE_NONE; } } else { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $scorm->maxgrade; $params['grademin'] = 0; } if ($grades === 'reset') { $params['reset'] = true; $grades = NULL; } return grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grades, $params); }
// Direct SCO request // if ($sco = scorm_get_sco($scoid)) { if ($sco->launch == '') { // Search for the next launchable sco if ($scoes = get_records_select('scorm_scoes', 'scorm=' . $scorm->id . " AND launch<>'" . sql_empty() . "' AND id>" . $sco->id, 'id ASC')) { $sco = current($scoes); } } } } // // If no sco was found get the first of SCORM package // if (!isset($sco)) { $scoes = get_records_select('scorm_scoes', 'scorm=' . $scorm->id . " AND launch<>'" . sql_empty() . "'", 'id ASC'); $sco = current($scoes); } if ($sco->scormtype == 'asset') { $attempt = scorm_get_last_attempt($scorm->id, $USER->id); $element = $scorm->version == 'scorm_13' || $scorm->version == 'SCORM_1.3' ? 'cmi.completion_status' : 'cmi.core.lesson_status'; $value = 'completed'; $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); } // // Forge SCO URL // $connector = ''; $version = substr($scorm->version, 0, 4); if (isset($sco->parameters) && !empty($sco->parameters) || $version == 'AICC') { if (stripos($sco->launch, '?') !== false) {
/** * Add an entry to the log table. * * Add an entry to the log table. These are "action" focussed rather * than web server hits, and provide a way to easily reconstruct what * any particular student has been doing. * * @uses $CFG * @uses $USER * @uses $db * @uses $REMOTE_ADDR * @uses SITEID * @param int $courseid The course id * @param string $module The module name - e.g. forum, journal, resource, course, user etc * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify. * @param string $url The file and parameters used to see the results of the action * @param string $info Additional description information * @param string $cm The course_module->id if there is one * @param string $user If log regards $user other than $USER */ function add_to_log($courseid, $module, $action, $url = '', $info = '', $cm = 0, $user = 0) { // Note that this function intentionally does not follow the normal Moodle DB access idioms. // This is for a good reason: it is the most frequently used DB update function, // so it has been optimised for speed. global $db, $CFG, $USER; if ($cm === '' || is_null($cm)) { // postgres won't translate empty string to its default $cm = 0; } if ($user) { $userid = $user; } else { if (!empty($USER->realuser)) { // Don't log return; } $userid = empty($USER->id) ? '0' : $USER->id; } $REMOTE_ADDR = getremoteaddr(); if (empty($REMOTE_ADDR)) { $REMOTE_ADDR = '0.0.0.0'; } $timenow = time(); $info = addslashes($info); if (!empty($url)) { // could break doing html_entity_decode on an empty var. $url = html_entity_decode($url); // for php < 4.3.0 this is defined in moodlelib.php } // Restrict length of log lines to the space actually available in the // database so that it doesn't cause a DB error. Log a warning so that // developers can avoid doing things which are likely to cause this on a // routine basis. $tl = textlib_get_instance(); if (!empty($info) && $tl->strlen($info) > 255) { $info = $tl->substr($info, 0, 252) . '...'; debugging('Warning: logged very long info', DEBUG_DEVELOPER); } // Note: Unlike $info, URL appears to be already slashed before this function // is called. Since database limits are for the data before slashes, we need // to remove them... $url = stripslashes($url); // If the 100 field size is changed, also need to alter print_log in course/lib.php if (!empty($url) && $tl->strlen($url) > 100) { $url = $tl->substr($url, 0, 97) . '...'; debugging('Warning: logged very long URL', DEBUG_DEVELOPER); } $url = addslashes($url); if (defined('MDL_PERFDB')) { global $PERF; $PERF->dbqueries++; $PERF->logwrites++; } $info = empty($info) ? sql_empty() : $info; // Use proper empties for each database $url = empty($url) ? sql_empty() : $url; $sql = 'INSERT INTO ' . $CFG->prefix . 'log (time, userid, course, ip, module, cmid, action, url, info) VALUES (' . "'{$timenow}', '{$userid}', '{$courseid}', '{$REMOTE_ADDR}', '{$module}', '{$cm}', '{$action}', '{$url}', '{$info}')"; $result = $db->Execute($sql); // MDL-11893, alert $CFG->supportemail if insert into log failed if (!$result && $CFG->supportemail) { $site = get_site(); $subject = 'Insert into log failed at your moodle site ' . $site->fullname; $message = "Insert into log table failed at " . date('l dS \\of F Y h:i:s A') . ".\n It is possible that your disk is full.\n\n"; $message .= "The failed SQL is:\n\n" . $sql; // email_to_user is not usable because email_to_user tries to write to the logs table, // and this will get caught in an infinite loop, if disk is full if (empty($CFG->noemailever)) { $lasttime = get_config('admin', 'lastloginserterrormail'); if (empty($lasttime) || time() - $lasttime > 60 * 60 * 24) { // limit to 1 email per day mail($CFG->supportemail, $subject, $message); set_config('lastloginserterrormail', time(), 'admin'); } } } if (!$result) { debugging('Error: Could not insert a new entry to the Moodle log', DEBUG_ALL); } }
function question_insert_q_ids($backup_unique_code, $info) { global $CFG; //put the ids of the questions from all these categories into the db. $status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids\n (backup_code, table_name, old_id, info)\n SELECT '{$backup_unique_code}', 'question', q.id, '" . sql_empty() . "'\n FROM {$CFG->prefix}question q, {$CFG->prefix}backup_ids bk\n WHERE q.category = bk.old_id AND bk.table_name = 'question_categories' \n AND " . sql_compare_text('bk.info') . " = '{$info}'\n AND bk.backup_code = '{$backup_unique_code}'", false); return $status; }
function scorm_simple_play($scorm, $user, $context) { $result = false; if ($scorm->updatefreq == UPDATE_EVERYTIME) { scorm_parse($scorm); } if (has_capability('mod/scorm:viewreport', $context)) { //if this user can view reports, don't skipview so they can see links to reports. return $result; } $scoes = get_records_select('scorm_scoes', 'scorm=' . $scorm->id . ' AND launch<>\'' . sql_empty() . '\'', 'id', 'id'); if ($scoes) { if ($scorm->skipview >= 1) { $sco = current($scoes); if (scorm_get_tracks($sco->id, $user->id) === false) { header('Location: player.php?a=' . $scorm->id . '&scoid=' . $sco->id); $result = true; } else { if ($scorm->skipview == 2) { header('Location: player.php?a=' . $scorm->id . '&scoid=' . $sco->id); $result = true; } } } } return $result; }
function certificate_activity_completed(&$activity, &$cm, $userid = 0) { global $CFG, $USER; static $quizid, $questid, $assid, $lessid, $feedid, $survid, $scormid, $facetofaceid; if (!$userid) { $userid = $USER->id; } if (empty($quizid)) { $quizid = get_field('modules', 'id', 'name', 'quiz'); $questid = get_field('modules', 'id', 'name', 'questionnaire'); $assid = get_field('modules', 'id', 'name', 'assignment'); $lessid = get_field('modules', 'id', 'name', 'lesson'); $feedid = get_field('modules', 'id', 'name', 'feedback'); $survid = get_field('modules', 'id', 'name', 'survey'); $scormid = get_field('modules', 'id', 'name', 'scorm'); $facetofaceid = get_field('modules', 'id', 'name', 'facetoface'); } /// If the module is not visible, it can't be accessed by students (assignment module /// will give us errors), so return true if its not visible. if (!empty($cm)) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { return true; } if ($cm->module == $quizid) { require_once $CFG->dirroot . '/mod/quiz/locallib.php'; $quiz = get_record('quiz', 'id', $cm->instance); $score = quiz_get_best_grade($quiz, $userid); $grade = (int) ((double) $score / (double) $quiz->grade * 100.0); return $grade >= (int) $activity->linkgrade; } else { if ($cm->module == $assid) { require_once $CFG->dirroot . '/mod/assignment/lib.php'; $assignment = get_record('assignment', 'id', $cm->instance); require_once "{$CFG->dirroot}/mod/assignment/type/{$assignment->assignmenttype}/assignment.class.php"; $assignmentclass = "assignment_{$assignment->assignmenttype}"; $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm); if (!($submission = $assignmentinstance->get_submission($userid))) { return false; } else { if ($assignmentinstance->assignment->grade <= 0) { return true; } else { $grade = (int) ((double) $submission->grade / (double) $assignmentinstance->assignment->grade * 100.0); return $grade >= (int) $activity->linkgrade; } } } else { if ($cm->module == $questid) { return get_record('questionnaire_attempts', 'qid', $cm->instance, 'userid', $userid) !== false; } else { if ($cm->module == $feedid) { return get_record('feedback_completed', 'feedback', $cm->instance, 'userid', $userid) !== false; } else { if ($cm->module == $survid) { return get_record('survey_answers', 'id', $cm->instance, 'userid', $userid) !== false; } else { if ($cm->module == $scormid) { require_once $CFG->dirroot . '/mod/scorm/locallib.php'; $scorm = get_record('scorm', 'id', $cm->instance); $score = scorm_grade_user($scorm, $userid); if ($scorm->grademethod % 10 == 0) { // GRADESCOES if (!($scorm->maxgrade = count_records_select('scorm_scoes', "scorm='{$scorm->id}' AND launch<>'" . sql_empty() . "'"))) { return true; } } $return->maxgrade = $scorm->maxgrade; $grade = (int) ((double) $score / (double) $scorm->maxgrade * 100.0); return $grade >= (int) $activity->linkgrade; } else { if ($cm->module == $lessid) { require_once $CFG->dirroot . '/mod/lesson/locallib.php'; if (!($lesson = get_record('lesson', 'id', $cm->instance))) { return true; } else { $ntries = count_records('lesson_grades', 'lessonid', $lesson->id, 'userid', $userid) - 1; $gradeinfo = lesson_grade($lesson, $ntries); return $gradeinfo->grade >= (int) $activity->linkgrade; } } else { if ($cm->module == $facetofaceid) { require_once $CFG->libdir . '/gradelib.php'; $grading_info = grade_get_grades($cm->course, 'mod', 'facetoface', $cm->instance, $userid); if (empty($grading_info)) { return false; } $grade = $grading_info->items[0]->grades[$userid]->grade; return $grade >= (int) $activity->linkgrade; } else { return true; } } } } } } } } } else { return true; } }