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 html5 implements ilm_handle { /// Produce HTML code to load iLM 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); $url = $iassign_ilm->file_class; // to HTML5 package, this 'file_class' must have the main HTML file 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 } if (!empty($file_url)) { // There is an iLM file //TODO iLM_HTML5 :: Change to 'object', tag 'applet' was deprecated. $paramsStr = "?1=1"; $html .= html5::show_ilm_commands(); switch ($options['type']) { case "view": $paramsStr .= "&iLM_PARAM_Assignment=" . urlencode($options['Proposition']); //leo $paramsStr .= "&iLM_PARAM_SendAnswer=true"; //TODO: REVIEW: this code is to insert iLM as HTML5 and to allow general parameter to any iLM //TODO: For now, 'iassign_ilm_config' is empty... let comment these lines //n $iassign_ilm_config = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_id)); //n foreach ($iassign_ilm_config as $ilm_config) { //n if (array_key_exists($ilm_config->param_name, $options)) { //n $ilm_config->param_value = $options[$ilm_config->param_name]; //n $paramsStr .= "&" . $ilm_config->param_name . "=" . urlencode($ilm_config->param_value); //n } //n } break; case "filter": if ($options['toolbar'] == "disable") $paramsStr .= "&SOH_ADD=ADD"; $paramsStr .= "&iLM_PARAM_AssignmentURL=true"; $paramsStr .= "&iLM_PARAM_Assignment=" . urlencode($options['Proposition']); $paramsStr .= "&iLM_PARAM_SendAnswer=" . urlencode($options['notSEND']); $paramsStr .= "&iLM_PARAM_ServerToGetAnswerURL=" . urlencode($ilm_config->param_value); break; // static function build_ilm_tags($ilm_id, $options=array()) case "activity": // build_ilm_tags //TODO To generalize to any HTML5 iLM, it is necessary to use 'iLM_PARAM_Assignment' and 'iLM_PARAM_SendAnswer' //TODO iLM_PARAM_Assignment=Proposition ; iLM_PARAM_SendAnswer=notSEND $paramsStr .= "&iLM_PARAM_AssignmentURL=true"; // if ($options['special_param'] == 1) { } $paramsStr .= "&iLM_PARAM_Assignment=" . urlencode($options['Proposition']); $paramsStr .= "&iLM_PARAM_SendAnswer=" . urlencode($options['notSEND']); $paramsStr .= "&iLM_PARAM_ServerToGetAnswerURL=" . urlencode($options['addresPOST']); //TODO iLM_HTML5 :: To extend to any iLM in HTML5 //TODO iLM_HTML5 :: it will allow to load dynamic parameters //T $iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $options['iassign_statement'] )); //T if ($iassign_activity_item_configs) { //T foreach ($iassign_activity_item_configs as $iassign_activity_item_config) //T $paramsStr .= "&" . $iassign_activity_item_config->param_name . "=" . urlencode($iassign_activity_item_config->param_value); //T } break; case "editor_new": $paramsStr .= "&iLM_PARAM_AssignmentURL=true"; $paramsStr .= "&iLM_PARAM_SendAnswer=" . urlencode($options['notSEND']); $paramsStr .= "&iLM_PARAM_Authoring=true"; break; case "editor_update": $paramsStr .= "&iLM_PARAM_AssignmentURL=true"; $paramsStr .= "&iLM_PARAM_Assignment=" . urlencode($options['Proposition']); $paramsStr .= "&iLM_PARAM_SendAnswer=" . urlencode($options['notSEND']); $paramsStr .= "&iLM_PARAM_Authoring=true"; break; default: $html .= iassign::warning_message_iassign('error_view_without_actiontype'); // $OUTPUT->notification(get_string('error_view_without_actiontype', 'iassign'), 'notifyproblem'); // The API allows for creation of four types of notification: error, warning, info, and success. } // switch($options['type']) $paramsStr .= "&lang=" . $lang; // get the language defined in Moodle $parameters = ' style="width: ' . $iassign_ilm_width . 'px; height: ' . $iassign_ilm_height . 'px;" '; $html .= '' . "\n"; } // if (!empty($file_url)) } // if ($iassign_ilm) return $html; } // public static function build_ilm_tags($ilm_id, $options = array()) public static function show_ilm_commands() { $html = ""; $html .= "