iMath) - Computer Science Dep. of IME-USP (Brazil)
*
* License
* - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
global $CFG;
require_once $CFG->dirroot . '/mod/iassign/ilm_handle.php';
class java implements ilm_handle {
/// Build HTML code to present an applet
public static function build_ilm_tags ($ilm_id, $options = array()) {
global $DB, $OUTPUT;
global $CONF_WWW; //TODO 1 => use iLM under WWW; otherwise use under MoodleData
$html = "";
if (empty($options['Proposition']))
$options['Proposition'] = "";
if (empty($options['addresPOST']))
$options['addresPOST'] = "";
if (empty($options['student_answer']))
$options['student_answer'] = "";
if (empty($options['notSEND']))
$options['notSEND'] = "";
else // Case it is authoring put 'notSEND' (important to iVProgH5 to present authoring tool)
if ($options['type'] == "editor_update")
$options['notSEND'] = "true";
if (empty($options['id_iLM_security'])) // if defined, it is from 'iassign_security'
$options['id_iLM_security'] = "";
$id_iLM_security = $options['id_iLM_security'];
$iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
if ($iassign_ilm) {
// md_files : filename
$ilm_extension = $iassign_ilm->extension; // use local variavel to efficiency (several use)
if ($ilm_extension) { // avoid problems
$ilm_extension = strtolower($ilm_extension);
}
// Attention: in iAssign 2014 on, all the iLM is located on the Moodle filesystem (usually /var/moodledata/filedir/).
// This means that '$iassign_ilm->file_jar' = '*_files.id'
/*$file_url = array();
$fs = get_file_storage();
$files_jar = explode(",", $iassign_ilm->file_jar);
foreach ($files_jar as $one_file) {
$file = $fs->get_file_by_id($one_file);
if (!$file)
print $OUTPUT->notification(get_string('error_confirms_jar', 'iassign'), 'notifyproblem');
else {
// Get file path (informatin on Moodle table '*_files' - in its field 'contenthash'
// The actual file is under the Moodle data. E.g., if Moodle data is the default '/var/moodledata' and 'contenthash="5641c1a0e1f5b37fa0b74996ead592c77ff027bc"',
// then the JAR file in: '/var/moodledata/fildir/56/41/5641c1a0e1f5b37fa0b74996ead592c77ff027bc'
$url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
array_push($file_url, $url);
}
}*/
$lang = substr(current_language(), 0, 2);
if ($options['type'] == "filter") { //leo
$iassign_ilm_width = $options['width']; // or use? $iassign_ilm->width
$iassign_ilm_height = $options['height']; // or use? $iassign_ilm->height
} else { //leo
$iassign_ilm_width = $iassign_ilm->width;
$iassign_ilm_height = $iassign_ilm->height; // or use? $iassign_ilm->height
}
$file_url = explode(",", $iassign_ilm->file_jar);
if (!empty($file_url)) { // There is an iLM file
// Build tag to JAR file
$html .= ' ' . "\n";
$html .= ' ' . "\n";
} // if (!empty($file_url))
} // if ($iassign_ilm)
return $html;
}
/// Presents an activity with its iLM
public static function show_activity_in_ilm ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
global $USER, $CFG, $DB;
$ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
// enderecoPOST: eliminei a tag '&write_solution=0' deixando para este 'view' completar, eventualmente com '&write_solution=1'!
$special_param1 = $iassign_statement_activity_item->special_param1;
$context = context_module::instance($USER->cm);
//TODO Given an activity => find its correspondent file in Moodle data. Bad solution!
//TODO Change the meaning of 'iassign_statement.file' from insertion order to the ID in table 'files'.
//TODO This demands update to each 'iassign_statement', find its corresponding on in 'files', and update 'iassign_statement.file = files.id'
if ($view_teacherfileversion) { // get the exercise in Moodle data (teacher file)
$fileid = "";
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file); // iassign_statement_activity_item = table 'iassign_statement'
if ($files) {
foreach ($files as $value) {
if ($value->get_filename() != '.')
$fileid = $value->get_id();
}
}
if (!$fileid) { // 'Something is wrong. Maybe your teacher withdrew this exercise file. Please, inform your teacher.';
print iassign::warning_message_iassign('error_exercise_removed') . " \n"; // I couldn't find the file in table 'files'!
}
}
$ilm_name = strtolower($ilm->name);
$extension = iassign_utils::filename_extension($ilm_name);
if ($ilm_name == "igeom") { // is iGeom exercise
$is_igeom = true;
$content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
if ($special_param1 == 1 && !empty($student_answer) && (!$view_teacherfileversion)) { // is script
$view_teacherfileversion = true; // here when student is doing/redoing his activity
}
elseif (!$view_teacherfileversion) { // Student seem his solution or teacher it (of one student)
$content_or_id_from_ilm_security = $student_answer;
}
}
else {
if ($view_teacherfileversion) { // $view_teacherfileversion==1 => load the exercise ('activity') from the 'moodledata' (id in 'files')
// $content_or_id_from_ilm_security = $this->context->id;
$content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
} else { // $view_teacherfileversion==null => load the learner answer from the data base (iassign_submission)
$content_or_id_from_ilm_security = $student_answer;
}
}
$allow_submission = false; // There is permission to 'submission' button?
if ($USER->iassignEdit == 1 && $student_answer) { // for now, only iVProg2 and iVProgH5 allows editions of exercise already sent
$allow_submission = true; // yes!
$write_solution = 1;
$enderecoPOST .= "&write_solution=1"; // complement POST address indicating that the learner could send edited solution
}
// Security: this avoid the student get a second access to the file content (usually an exercise)
// Data are registered in the table '*_iassign_security' bellow and is erased by function 'view()' above.
// IMPORTANT: the '$end_file' will receive the iLM content URL using the security filter './mod/iassign/ilm_security.php'
// the iLM must request the content using this URL. Data are registered in the table '*_iassign_security'.
// Attention : using iVProgH5 there are lot of " and the use of slashes (as '\"') will imply in iVProgH5 do not read the file!
// do not use: $id_iLM_security = $this->write_iLM_security($iassign_statement_activity_item->id, addslashes($content_or_id_from_ilm_security));
//2017 $id_iLM_security = $this->write_iLM_security($iassign_statement_activity_item->id, $content_or_id_from_ilm_security); // insert in 'iassign_security'
//2017 $this->remove_old_iLM_security_entries($USER->id, $iassign_statement_activity_item->id); // additional security: erase eventually old entries
require_once ($CFG->dirroot . '/mod/iassign/ilm_security.php');
$timecreated = time();
$token = md5($timecreated); // iassign_iLM_security->timecreated);
// Try to get the student answer
// In './ilm_security.php': write_iLM_security($userid, $timecreated, $iassign_statementid = -1, $content_or_id_from_ilm_security)
$id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, $iassign_statement_activity_item->id, $content_or_id_from_ilm_security); // insert in 'iassign_security'
// $iassign_iLM_security = $DB->get_record("iassign_security", array("id" => $id_iLM_security));
$end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $id_iLM_security . '&token=' . $token . '&view=' . $view_teacherfileversion; // need full path...
//TODO iLM_HTML5 :: Need to use '*_iassign_ilm.ilm_type' in { 'jar', 'html5' }
//TODO iLM_HTML5 :: For now I use the particular case of
//leo Ou usar: if ($extension == "html" || $extension == "ivph") // if iLM is HTML5 is inside a frame
$iassign = "
\n"; //
$iassign .= "\n
\n
\n\n";
return $iassign;
}
/**
* Exibe os dados de um iLM
*/
public static function view_ilm($ilmid, $from) {
global $DB;
$url = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
$iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
$str = "";
$str .= '
' . "\n";
}
if (!empty($iassign_ilm->file_jar)) {
//TODO: REVIEW: to be used for parameters of "applet" from DB
$options = array("type" => "view"); //MOOC2014: start
$str .= '
' . "\n";
// Second parameter null since 'iassign_security' are not define yet
$str .= ilm_settings::build_ilm_tags($iassign_ilm->id, $options);
//TODO: REVIEW: missing code to manage parameters
//MOOC2014: tem este codigo!
} else {
$str .= '