function list_activities($vplid) { global $DB; $list = array('' => ''); $cn = $this->vpl->get_course()->shortname; //Low privilegies $courses = get_user_capability_course(VPL_VIEW_CAPABILITY, null, true, 'shortname'); //Reorder courses by name similar to current usort($courses, function ($a, $b) use($cn) { $na = $a->shortname; $nb = $b->shortname; $da = levenshtein($na, $cn); $db = levenshtein($nb, $cn); if ($da != $db) { return $da < $db ? -1 : 1; } if ($na == $cn) { return -1; } if ($nb == $cn) { return 1; } if ($na != $nb) { return $na < $nb ? -1 : 1; } return 0; }); foreach ($courses as $course) { $vpls = $DB->get_records(VPL, array('course' => $course->id)); foreach ($vpls as $vplinstace) { if ($vplinstace->id == $vplid) { continue; } $othervpl = new mod_vpl(false, $vplinstace->id); if (!$othervpl->get_course_module()) { continue; } if ($othervpl->has_capability(VPL_SIMILARITY_CAPABILITY)) { $list[$othervpl->get_course_module()->id] = $othervpl->get_course()->shortname . ' ' . $othervpl->get_printable_name(); } } if (count($list) > 1000) { break; //Stop loading instances } } $list[''] = get_string('select'); return $list; }
$mform->setDefault('automaticgrading', 1); $mform->disabledIf('automaticgrading', 'evaluate', 'eq', 0); $mform->addElement('submit', 'saveoptions', get_string('saveoptions', VPL)); } } require_login(); $id = required_param('id', PARAM_INT); $vpl = new mod_vpl($id); $vpl->prepare_page('forms/executionoptions.php', array('id' => $id)); vpl_include_jsfile('hideshow.js'); $vpl->require_capability(VPL_MANAGE_CAPABILITY); //Display page $vpl->print_header(get_string('execution', VPL)); $vpl->print_heading_with_help('executionoptions'); $vpl->print_configure_tabs(basename(__FILE__)); $course = $vpl->get_course(); $fgp = $vpl->get_execution_fgm(); $mform = new mod_vpl_executionoptions_form('executionoptions.php', $vpl); if ($fromform = $mform->get_data()) { if (isset($fromform->saveoptions)) { $instance = $vpl->get_instance(); \mod_vpl\event\vpl_execution_options_updated::log($vpl); $instance->basedon = $fromform->basedon; $instance->run = $fromform->run; $instance->debug = $fromform->debug; $instance->evaluate = $fromform->evaluate; $instance->evaluateonsubmission = $fromform->evaluate && $fromform->evaluateonsubmission; $instance->automaticgrading = $fromform->evaluate && $fromform->automaticgrading; if ($DB->update_record(VPL, $instance)) { vpl_notice(get_string('optionssaved', VPL)); } else {
$outcome->response = new stdClass(); $outcome->error = ''; try { require_once dirname(__FILE__) . '/../../../config.php'; require_once dirname(__FILE__) . '/edit.class.php'; if (!isloggedin()) { throw new Exception(get_string('loggedinnot')); } $id = required_param('id', PARAM_INT); // course id $action = required_param('action', PARAM_ALPHANUMEXT); $userid = optional_param('userid', FALSE, PARAM_INT); $vpl = new mod_vpl($id); //TODO use or not sesskey //require_sesskey(); require_login($vpl->get_course(), false); $PAGE->set_url(new moodle_url('/mod/vpl/forms/editor.json.php', array('id' => $id, 'action' => $action))); echo $OUTPUT->header(); // Send headers. $raw_data = file_get_contents("php://input"); $raw_data_size = strlen($raw_data); if ($_SERVER['CONTENT_LENGTH'] != $raw_data_size) { throw new Exception("Ajax POST error: CONTENT_LENGTH expected " . $_SERVER['CONTENT_LENGTH'] . " found {$raw_data_size})"); } $data = json_decode($raw_data); if (!$vpl->is_submit_able()) { throw new Exception(get_string('notavailable')); } if (!$userid || $userid == $USER->id) { // Make own submission $userid = $USER->id;
function vpl_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0) { global $CFG, $USER, $DB; $grader = false; $vpl = new mod_vpl($cmid); $modinfo =& get_fast_modinfo($vpl->get_course()); $cm = $modinfo->cms[$cmid]; if ($vpl->is_visible()) { $vplid = $vpl->get_instance()->id; $grader = $vpl->has_capability(VPL_GRADE_CAPABILITY); } else { return; } $select = '(vpl = ?)'; $select .= ' and ((datesubmitted >= ?) or (dategraded >= ?))'; $parms = array($vplid, $timestart, $timestart); if (!$grader) { //Own activity array_unshift($parms, $USER->id); $select = '(userid = ?) and ' . $select; } $subs = $DB->get_records_select(VPL_SUBMISSIONS, $select, $parms, 'datesubmitted DESC'); $aname = format_string($vpl->get_printable_name(), true); foreach ($subs as $sub) { //Show recent activity $activity = new stdClass(); $activity->type = 'vpl'; $activity->cmid = $cm->id; $activity->name = $aname; $activity->sectionnum = $cm->sectionnum; $activity->timestamp = $sub->datesubmitted; if ($grader) { $activity->grade = $sub->grade; } $activity->user = $DB->get_record('user', array('id' => $sub->userid)); $activities[$index++] = $activity; } return true; }
//Make other user submission $vpl->require_capability(VPL_MANAGE_CAPABILITY); } $instance = $vpl->get_instance(); $vpl->print_header(get_string('submission', VPL)); $vpl->print_view_tabs(basename(__FILE__)); $mform = new mod_vpl_submission_form('submission.php', $vpl); if ($mform->is_cancelled()) { vpl_inmediate_redirect(vpl_mod_href('view.php', 'id', $id)); die; } if ($fromform = $mform->get_data()) { $raw_POST_size = strlen(file_get_contents("php://input")); if ($_SERVER['CONTENT_LENGTH'] != $raw_POST_size) { $error = "NOT SAVED (Http POST error: CONTENT_LENGTH expected " . $_SERVER['CONTENT_LENGTH'] . " found {$raw_POST_size})"; notice($error, vpl_mod_href('forms/submission.php', 'id', $id, 'userid', $userid), $vpl->get_course()); die; } $rfn = $vpl->get_required_fgm(); $minfiles = count($rfn->getFilelist()); $files = array(); for ($i = 0; $i < $instance->maxfiles; $i++) { $attribute = 'file' . $i; $name = $mform->get_new_filename($attribute); $data = $mform->get_file_content($attribute); if ($data !== false && $name !== false) { //autodetect data file encode $encode = mb_detect_encoding($data, 'UNICODE, UTF-16, UTF-8, ISO-8859-1', true); if ($encode > '') { //If code detected $data = iconv($encode, 'UTF-8', $data);