123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- <?php
- global $CFG;
- require_once $CFG->dirroot . '/mod/iassign/ilm_handle.php';
- class html5 implements ilm_handle {
-
- public static function build_ilm_tags ($ilm_id, $options = array()) {
- global $DB, $OUTPUT;
- global $CONF_WWW;
- $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
- if ($options['type'] == "editor_update")
- $options['notSEND'] = "true";
- if (empty($options['id_iLM_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) {
-
- $ilm_extension = $iassign_ilm->extension;
- if ($ilm_extension) {
- $ilm_extension = strtolower($ilm_extension);
- }
-
-
- $file_url = array();
- $fs = get_file_storage();
- $files_jar = explode(",", $iassign_ilm->file_jar);
- $url = $iassign_ilm->file_class;
- array_push($file_url, $url);
- $lang = substr(current_language(), 0, 2);
- if ($options['type'] == "filter") {
- $iassign_ilm_width = $options['width'];
- $iassign_ilm_height = $options['height'];
- } else {
- $iassign_ilm_width = $iassign_ilm->width;
- $iassign_ilm_height = $iassign_ilm->height;
- }
- if (!empty($file_url)) {
-
- $paramsStr = "?1=1";
- $html .= html5::show_ilm_commands();
- switch ($options['type']) {
- case "view":
- $paramsStr .= "&iLM_PARAM_Assignment=" . urlencode($options['Proposition']);
- $paramsStr .= "&iLM_PARAM_SendAnswer=true";
-
-
-
-
-
-
-
-
-
- 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;
- case "activity":
-
-
- $paramsStr .= "&iLM_PARAM_AssignmentURL=true";
-
- $paramsStr .= "&iLM_PARAM_Assignment=" . urlencode($options['Proposition']);
- $paramsStr .= "&iLM_PARAM_SendAnswer=" . urlencode($options['notSEND']);
- $paramsStr .= "&iLM_PARAM_ServerToGetAnswerURL=" . urlencode($options['addresPOST']);
-
-
-
-
-
-
-
- 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');
- }
- $paramsStr .= "&lang=" . $lang;
- $parameters = ' style="width: ' . $iassign_ilm_width . 'px; height: ' . $iassign_ilm_height . 'px;" ';
- $html .= '<iframe frameborder="0" name="iLM" id="iLM" src="' . $iassign_ilm->file_jar . $iassign_ilm->file_class . $paramsStr . '" ' . $parameters . '>' . "\n";
- $html .= '</iframe>' . "\n";
- }
- }
- return $html;
- }
- public static function show_ilm_commands() {
- $html = "<script>function full_screen() {
- if('fullscreenEnabled' in document || 'webkitFullscreenEnabled' in document || 'mozFullScreenEnabled' in document || 'msFullscreenEnabled' in document) {
- if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
- var element = document.getElementsByName('iLM').item(0);
- //requestFullscreen is used to display an element in full screen mode.
- if('requestFullscreen' in element) {
- element.requestFullscreen();
- }
- else if ('webkitRequestFullscreen' in element) {
- element.webkitRequestFullscreen();
- }
- else if ('mozRequestFullScreen' in element) {
- element.mozRequestFullScreen();
- }
- else if ('msRequestFullscreen' in element) {
- element.msRequestFullscreen();
- }
- }
- } else {
- $('.expand_button').addClass('disabled');
- }
- }</script>";
- $html .= "<div style='width: 800px;text-align: right;'><div onClick='full_screen()' style='color: blue; cursor: pointer; display: contents;'>".get_string('full_screen', 'iassign')."</div></div>";
- return $html;
- }
-
-
- public static function show_activity_in_ilm ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT;
- $special_param1 = $iassign_statement_activity_item->special_param1;
- $ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
- $context = context_module::instance($USER->cm);
-
-
-
- if ($view_teacherfileversion) {
- $fileid = "";
- $fs = get_file_storage();
- $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
- if ($files) {
- foreach ($files as $value) {
- if ($value->get_filename() != '.')
- $fileid = $value->get_id();
- }
- }
- if (!$fileid) {
- print iassign::warning_message_iassign('error_exercise_removed') . "<br/>\n";
- }
- }
- $ilm_name = strtolower($ilm->name);
- $extension = iassign_utils::filename_extension($ilm_name);
- if ($view_teacherfileversion) {
-
- $content_or_id_from_ilm_security = $fileid;
- }
- else {
- $content_or_id_from_ilm_security = $student_answer;
- }
- $allow_submission = false;
-
- if ($USER->iassignEdit == 1 && $student_answer) {
- $allow_submission = true;
- $write_solution = 1;
- $enderecoPOST .= "&write_solution=1";
- }
-
-
-
-
-
-
-
-
- require_once ($CFG->dirroot . '/mod/iassign/ilm_security.php');
- $timecreated = time();
- $token = md5($timecreated);
- $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, $iassign_statement_activity_item->id, $content_or_id_from_ilm_security);
-
- $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $id_iLM_security . '&token=' . $token . '&view=' . $view_teacherfileversion;
-
- $iassign = "
- <script type='text/javascript'>
- //<![CDATA[
- var strAnswer = '';
- var evaluationResult = '';
- var comment = '';
- function jsAnalyseAnswer () {
- // iVProgH5 will call function 'getEvaluationCallback(...)': /var/www/html/ivprogh5/js/services.js
- // 'getEvaluation()' calls 'js/services.js : endTest function(index)' that calls 'getEvaluationCallback(apro/100);'
- // sumEval = getSummation(); alert('mod/iassign/ilm/ifractions_5/index.html: sumEval = ' + sumEval);
- //CUIDADO 2017/11/22 - usar 'window.frames.iLM' resultava neste ponto 'TypeError: window.frames.iLM.getEvaluation is not a function'
- //CUIDADO resp = window.frames.iLM.getEvaluation();
- resp = window.frames[0].getEvaluation(); // pegar diretamente a primeir janela (nao pode haver outra!)
- if (resp == 'undefined') // in './mod/iassign/ilm/ivprog-html/js/services.js'; './mod/iassign/ilm/ivprog-html/main.html'
- return false;
- return true;
- }
- // ./mod/iassign/ilm/ivprog-html/js/services.js : call this to define the variable 'evaluationResult'
- function getEvaluationCallback (evaluation) {
- evaluationResult = evaluation;
- //leo 2017/11/22 strAnswer = window.frames.iLM.getAnswer();
- strAnswer = window.frames[0].getAnswer();
- // alert('getEvaluationCallback(...)' + evaluation + ', strAnswer=' + strAnswer);
- comment = document.formEnvio.submission_comment.value;
- //leo alert('getEvaluationCallback: enviando evaluationResult=' + evaluation + ', strAnswer=' + strAnswer);
- //leo
- if ((strAnswer==null || strAnswer=='' || strAnswer==-1) && (comment==null || comment=='')) { // undefined
- alert('" . get_string('activity_empty', 'iassign') . "'); // 'Activity sent without content.'
- return false; // error...
- }
- else {
- document.formEnvio.iLM_PARAM_ArchiveContent.value = strAnswer;
- document.formEnvio.iLM_PARAM_ActivityEvaluation.value = evaluationResult;
- document.formEnvio.iLM_PARAM_RealGrade.value = evaluation;
- //D alert(strAnswer);
- document.formEnvio.submit();
- return true; // success
- }
- }
- //]]>
- </script>\n";
- $iassign .= "\n<center>\n<form name='formEnvio' id='formEnvio' method='post' action='$enderecoPOST' enctype='multipart/form-data'>\n";
-
-
-
-
-
- $iassign .= ilm_settings::build_ilm_tags($ilm->id, array(
- "type" => "activity",
- "notSEND" => "false",
- "addresPOST" => $enderecoPOST,
- "Proposition" => $end_file,
- "special_param" => $special_param1,
- "student_answer" => $student_answer,
- "id_iLM_security" => $id_iLM_security,
- "iassign_statement" => $iassign_statement_activity_item->id
- ));
-
-
-
-
-
-
- if (!isguestuser() && $iassign_statement_activity_item->type_iassign != 1
- && ($ilm->editingbehavior == 1 || ($ilm->editingbehavior == 0 && !in_array($_GET['action'], array('viewsubmission', 'view'))))) {
- $iassign .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>\n";
- $iassign .= " <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>\n";
- $iassign .= " <input type='hidden' name='iLM_PARAM_RealGrade' value=''>\n";
- if (!has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
- $iassign .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
- else
- $iassign .= "<input type='hidden' name='submission_comment'>\n";
-
- if ($allow_submission) {
- $iassign .= "<center>\n<!-- load button -->\n" .
- " <input type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
- get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
- } else {
-
- $iassign .= "<center>\n<!-- load button -->\n" .
- " <input type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
- get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
- }
- }
- elseif ($ilm->editingbehavior == 0) {
-
- $iassign .= "<center><br><a href=\"view.php?action=repeat&id=".$_GET['id']
- ."&iassign_current=".$_GET['iassign_current']."\">
- <input type='button' value='".get_string('repeat', 'iassign')."'></a></center>";
- }
-
- $iassign .= "</form></center>\n\n";
- return $iassign;
- }
-
- 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 .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
- $str .= '<tr>';
- $str .= '<td colspan=3 align=right>';
- if ($from != 'admin') {
- $str .= '<input type=button value="' . get_string('return', 'iassign') . '" onclick="javascript:window.location = \'' . $_SERVER['HTTP_REFERER'] . '\';">' . "\n";
- }
- $str .= '<input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close();">';
- $str .= '</td>' . "\n";
- $str .= '</tr>' . "\n";
- if ($iassign_ilm) {
- $iassign_statement_activity_item = $DB->get_records('iassign_statement', array("iassign_ilmid" => $iassign_ilm->id));
- if ($iassign_statement_activity_item) {
- $total = count($iassign_statement_activity_item);
- } else {
- $total = 0;
- }
- if ($from == 'admin') {
- $str .= '<tr><td colspan=2>' . "\n";
- $str .= '<table width="100%" class="generaltable boxaligncenter" >' . "\n";
- $str .= '<tr>' . "\n";
- $str .= '<td class=\'cell c0 actvity\' ><strong>' . get_string('activities', 'iassign') . ':</strong> ' . $total . '</td>' . "\n";
- $str .= '<td><strong>' . get_string('url_ilm', 'iassign') . '</strong> <a href="' . $iassign_ilm->url . '">' . $iassign_ilm->url . '</a></td>' . "\n";
- $str .= '</tr>' . "\n";
- $str .= '<tr><td colspan=2><strong>' . get_string('description', 'iassign') . ':</strong> ' . iassign_language::get_description_lang(current_language(), $iassign_ilm->description) . '</td></tr>' . "\n";
- $str .= '<tr><td width="50%"><strong>' . get_string('type_ilm', 'iassign') . ':</strong> ' . $iassign_ilm->type . ' <strong>' . get_string('extension', 'iassign') . ':</strong> ' . $iassign_ilm->extension . '</td>' . "\n";
- $str .= '<td width="50%"><strong>' . get_string('width', 'iassign') . ':</strong> ' . $iassign_ilm->width;
- $str .= ' <strong>' . get_string('height', 'iassign') . ':</strong> ' . $iassign_ilm->height . '</td></tr>' . "\n";
- $date_jar = $iassign_ilm->file_jar;
- $str .= '<tr><td><strong>' . get_string('file_jar', 'iassign') . ':</strong> ' . $date_jar . '</td>' . "\n";
- $str .= '<td ><strong>' . get_string('file_class', 'iassign') . ':</strong> ' . $iassign_ilm->file_class . '</td></tr>' . "\n";
- if ($iassign_ilm->evaluate == 1) {
- $evaluate = get_string('yes', 'iassign');
- } else {
- $evaluate = get_string('no', 'iassign');
- }
- $str .= '<tr><td width="50%"><strong>' . get_string('evaluate', 'iassign') . ':</strong> ' . $evaluate . '</td>' . "\n";
- if ($iassign_ilm->enable == 1) {
- $enable = get_string('yes', 'iassign');
- } else {
- $enable = get_string('no', 'iassign');
- }
- $str .= '<td width="50%"><strong>' . get_string('enable', 'iassign') . ':</strong> ' . $enable . '</td></tr>' . "\n";
- $str .= '<tr>' . "\n";
- $str .= '<td width="50%"><strong>' . get_string('file_created', 'iassign') . ':</strong> ' . userdate($iassign_ilm->timecreated) . '</td>' . "\n";
- $str .= '<td width="50%"><strong>' . get_string('file_modified', 'iassign') . ':</strong> ' . userdate($iassign_ilm->timemodified) . '</td>' . "\n";
- $str .= '</tr>' . "\n";
- $user_ilm = $DB->get_record('user', array('id' => $iassign_ilm->author));
- if ($user_ilm) {
- $str .= '<tr>' . "\n";
- $str .= '<td colspan=2><strong>' . get_string('author', 'iassign') . ':</strong> ' . $user_ilm->firstname . ' ' . $user_ilm->lastname . '</td>' . "\n";
- $str .= '</tr>' . "\n";
- }
- $str .= '</table>' . "\n";
- $str .= '</td></tr>' . "\n";
- }
- if (!empty($iassign_ilm->file_jar)) {
-
- $options = array("type" => "view");
- $str .= '<tr class=\'cell c0 actvity\'><td colspan=3 align=center bgcolor="#F5F5F5">' . "\n";
-
- $str .= ilm_settings::build_ilm_tags($iassign_ilm->id, $options);
-
-
- } else {
- $str .= '<tr class=\'cell c0 actvity\'>' . "\n";
- $str .= '<td colspan=2 align=center>' . get_string('null_file', 'iassign') . '</td>' . "\n";
- $str .= '<td align=center><a href="' . $url . '</a></td>' . "\n";
- $str .= '</tr>' . "\n";
- }
- $str .= '</td></tr>' . "\n";
- }
- $str .= '</table>' . "\n";
- return $str;
- }
-
-
- public static function copy_new_version_ilm ($param, $files_extract) {
- global $DB, $CFG;
- $iassign_ilm = new stdClass();
- $iassign_ilm->name = $param->name;
- $iassign_ilm->version = $param->version;
- $iassign_ilm->file_jar = null;
- $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
- $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
- if ($file_jar == null) {
- return false;
- }
- $file_jar = str_replace("./", "", $file_jar) . "/";
-
-
-
- $description_json_lang = $param->description_lang;
- $newentry = new stdClass();
- $newentry->name = $param->name;
- $newentry->version = $param->version;
- $newentry->type = 'HTML5';
- $newentry->url = $param->url;
- $newentry->description = $description_json_lang;
- $newentry->extension = strtolower($param->extension);
- $newentry->file_jar = $file_jar;
- $newentry->file_class = $param->file_class;
- $newentry->width = $param->width;
- $newentry->height = $param->height;
- $newentry->enable = 0;
- $newentry->timemodified = $param->timemodified;
- $newentry->timecreated = $param->timecreated;
- $newentry->evaluate = $param->evaluate;
- $newentry->author = $param->author;
- $newentry->parent = $param->parent;
- $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
-
- iassign_log::add_log('copy_iassign_ilm', 'name: ' . $param->name . ' ' . $param->version, 0, $newentry->id);
-
- }
-
- public static function export_ilm ($ilm_id) {
- global $DB, $CFG;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
- $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_id));
- if (!$iassign_ilm_configs) return;
- $files_jar = $iassign_ilm->file_jar;
- $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '_' . date("Ymd-Hi") . '.ipz';
- $zip = new zip_archive;
- $zip->open($zip_filename);
- $rootdir = $CFG->dirroot . '/mod/iassign/' . $files_jar;
- $first_folder = str_replace($CFG->dirroot . '/mod/iassign/ilm/', "", $rootdir);
- $zip->add_directory($first_folder);
- $allfiles = self::list_directory($rootdir);
- $i = 0;
- foreach ($allfiles as $file) {
- $mini = str_replace($CFG->dirroot . '/mod/iassign/ilm/', "", $file);
- $mini = str_replace('//', "/", $mini);
- if (is_dir($file)) {
- $zip->add_directory($mini);
- } else {
- $zip->add_file_from_pathname($mini, $file);
- }
- }
- $folder = str_replace('ilm/', "", $files_jar);
- $application_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
- $application_descriptor .= '<application xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
- $application_descriptor .= ' <name>' . $iassign_ilm->name . '</name>' . "\n";
- $application_descriptor .= ' <url>' . $iassign_ilm->url . '</url>' . "\n";
- $application_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
- $application_descriptor .= ' <type>' . $iassign_ilm->type . '</type>' . "\n";
- $application_descriptor .= ' <description>' . html_entity_decode(str_replace(array('<p>', '</p>'), array('', ''), $iassign_ilm->description)) . '</description>' . "\n";
- $application_descriptor .= ' <extension>' . $iassign_ilm->extension . '</extension>' . "\n";
- $application_descriptor .= ' <file_jar>' . $folder . '</file_jar>' . "\n";
- $application_descriptor .= ' <file_class>' . $iassign_ilm->file_class . '</file_class>' . "\n";
- $application_descriptor .= ' <width>' . $iassign_ilm->width . '</width>' . "\n";
- $application_descriptor .= ' <height>' . $iassign_ilm->height . '</height>' . "\n";
- $application_descriptor .= ' <evaluate>' . $iassign_ilm->evaluate . '</evaluate>' . "\n";
- $application_descriptor .= ' <reevaluate>' . $iassign_ilm->reevaluate . '</reevaluate>' . "\n";
- if ($iassign_ilm_configs) {
- $application_descriptor .= ' <params>' . "\n";
- foreach ($iassign_ilm_configs as $iassign_ilm_config) {
- $application_descriptor .= ' <param>' . "\n";
- $application_descriptor .= ' <type>' . $iassign_ilm_config->param_type . '</type>' . "\n";
- $application_descriptor .= ' <name>' . $iassign_ilm_config->param_name . '</name>' . "\n";
- $application_descriptor .= ' <value>' . $iassign_ilm_config->param_value . '</value>' . "\n";
- $application_descriptor .= ' <description>' . htmlentities(str_replace("\n", "", $iassign_ilm_config->description)) . '</description>' . "\n";
- $application_descriptor .= ' <visible>' . $iassign_ilm_config->visible . '</visible>' . "\n";
- $application_descriptor .= ' </param>' . "\n";
- }
- $application_descriptor .= ' </params>' . "\n";
- }
- $application_descriptor .= '</application>' . "\n";
- $zip->add_file_from_string('ilm-application.xml', $application_descriptor);
- $zip->close();
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: private", false);
- header("Content-Type: application/zip");
- header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
- header("Content-Transfer-Encoding: binary");
- header("Content-Length: " . (filesize($zip_filename)));
- set_time_limit(0);
- readfile($zip_filename) || die("File not found.");
- unlink($zip_filename);
- exit;
- }
-
-
-
- static function list_directory ($dir) {
- $files = array();
- $cont = 0;
- $ffs = scandir($dir);
- unset($ffs[array_search('.', $ffs, true)]);
- unset($ffs[array_search('..', $ffs, true)]);
- if (count($ffs) < 1) {
- return;
- }
- foreach ($ffs as $ff) {
- $files[$cont] = $dir . "/" . $ff;
- $cont++;
- if (is_dir($dir . '/' . $ff)) {
- $temp = self::list_directory($dir . '/' . $ff);
- foreach ($temp as $t) {
- $files[$cont] = $t;
- $cont++;
- }
- }
- }
- return $files;
- }
- public static function delete_ilm($ilm_id) {
- global $DB, $CFG, $OUTPUT;
- $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
-
- $path_w = rtrim($iassign_ilm->file_jar, "/");
- $folder_to_remove = substr($path_w, 0, strrpos($path_w, '/') + 1);
-
- if (!is_writable($iassign_ilm->file_jar)) {
- return null;
- }
- self::delete_dir($folder_to_remove);
- $ilm_folder = "ilm/" . $iassign_ilm->name . "/";
- $k = 0;
-
- foreach(glob($ilm_folder . "*", GLOB_ONLYDIR) as $dir) {
- $k ++;
- break;
- }
- if ($k == 0) {
- self::delete_dir($ilm_folder);
- }
- $DB->delete_records("iassign_ilm", array('id' => $ilm_id));
- $DB->delete_records("iassign_ilm_config", array('iassign_ilmid' => $ilm_id));
-
- iassign_log::add_log('delete_iassign_ilm', 'name: ' . $iassign_ilm->name . ' ' . $iassign_ilm->version, 0, $iassign_ilm->id);
-
- return $iassign_ilm->parent;
- }
-
-
- public static function edit_ilm ($param, $itemid, $files_extract, $contextuser) {
- global $DB, $CFG;
- $iassign_ilm = new stdClass();
- $iassign_ilm->name = $param->name;
- $iassign_ilm->version = $param->version;
- $iassign_ilm->file_jar = $param->file_jar;
- $file_jar = null;
- if (!is_null($files_extract)) {
- $file_jar = self::save_ilm_by_xml(null, $files_extract);
- if ($file_jar == null) {
- return false;
- }
- $file_jar = str_replace("./", "", $file_jar) . "/";
- }
- if (is_null($file_jar)) {
-
- $file_jar = $param->file_jar;
- }
- $description = json_decode($param->description_lang);
- $description->{$param->set_lang} = $param->description;
- $updentry = new stdClass();
- $updentry->id = $param->id;
- $updentry->version = $param->version;
- $updentry->url = $param->url;
-
-
- $updentry->description = json_encode($description, JSON_UNESCAPED_UNICODE);
- $updentry->extension = strtolower($param->extension);
- if (!is_null($file_jar)) {
- $updentry->file_jar = $file_jar;
- }
- $updentry->file_class = $param->file_class;
- $updentry->width = $param->width;
- $updentry->height = $param->height;
- $updentry->enable = $param->enable;
- $updentry->timemodified = $param->timemodified;
- $updentry->evaluate = $param->evaluate;
-
- $DB->update_record("iassign_ilm", $updentry);
-
- iassign_log::add_log('update_iassign_ilm', 'name: ' . $param->name . ' ' . $param->version, 0, $param->id);
-
- }
-
-
-
-
- static function new_file_ilm ($itemid, $fs, $contextuser, $contextsystem, $files_ilm) {
- global $CFG, $USER, $DB;
- if ($files_ilm) {
- foreach ($files_ilm as $value) {
-
-
- $destination = 'ilm_debug/' . $value->get_filename();
- $value->copy_content_to($destination);
-
- $zip = new ZipArchive();
- $extracted = './ilm';
- $dir = "";
- if ($zip->open($destination) === TRUE) {
- $dir = './ilm/' . trim($zip->getNameIndex(0));
- if (is_dir($dir)) {
- $i = 1;
- $previous = str_replace("/", "", $zip->getNameIndex(0));
- while (file_exists('./ilm/' . $previous . "_" . $i)) {
- $i ++;
- }
- $name = $previous . "_" . $i;
- $dir = './ilm/' . $name . "/";
- $j = 0;
- while ($item_name = $zip->getNameIndex($j)) {
- $zip->renameIndex($j, str_replace($previous, $name, $item_name));
- $j++;
- }
- $zip->close();
- }
- $zip->open($destination);
- $zip->extractTo($extracted);
- $zip->close();
-
- unlink($destination);
- } else {
-
- unlink($destination);
- print_error('error_add_ilm_zip', 'iassign');
- }
- return $dir;
- }
- }
- }
-
- public static function new_ilm ($itemid, $files_extract, $application_xml, $contextuser, $fs) {
- global $DB, $CFG, $USER, $OUTPUT;
- $description_str = str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML());
- $iassign_ilm = $DB->get_record('iassign_ilm', array("name" => (String) $application_xml->name, "version" => (String) $application_xml->version));
- if ($iassign_ilm) {
- foreach ($files_extract as $key => $value) {
- $rootfolder = $CFG->dataroot . '/temp/' . $key;
- self::delete_dir($rootfolder);
- break;
- }
- print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
- return false;
- }
- else {
- $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
- if ($file_jar == null) {
- return false;
- }
- $file_jar = str_replace("./", "", $file_jar);
- if (empty($file_jar)) {
- $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In new_ilm: file_jar empty, files_extract=" . $files_extract . "<br/>\n";
- print_error($msg_error);
-
-
- }
- else {
- $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
- if (!$iassign_ilm) {
- $iassign_ilm = new stdClass();
- $iassign_ilm->id = 0;
- }
- $newentry = new stdClass();
- $newentry->name = (String) $application_xml->name;
- $newentry->version = (String) $application_xml->version;
- $newentry->type = (String) $application_xml->type;
- $newentry->url = (String) $application_xml->url;
- $newentry->description = strip_tags($description_str);
- $newentry->extension = strtolower((String) $application_xml->extension);
- $newentry->file_jar = $file_jar . "/";
- $newentry->file_class = (String) $application_xml->file_class;
- $newentry->width = (String) $application_xml->width;
- $newentry->height = (String) $application_xml->height;
- $newentry->enable = 0;
- $newentry->timemodified = time();
- $newentry->author = $USER->id;
- $newentry->timecreated = time();
- $newentry->evaluate = (String) $application_xml->evaluate;
- $newentry->reevaluate = (String) $application_xml->reevaluate;
- $newentry->parent = $iassign_ilm->id;
- $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
-
- iassign_log::add_log('add_iassign_ilm', 'name: ' . $newentry->name . ' ' . $newentry->version, 0, $newentry->id);
-
- if ($application_xml->params->param) {
- foreach ($application_xml->params->param as $value) {
- $newentry = new stdClass();
- $newentry->iassign_ilmid = $iassign_ilmid;
- $newentry->param_type = (String) $value->type;
- $newentry->param_name = (String) $value->name;
- $newentry->param_value = (String) $value->value;
- $newentry->description = html_entity_decode((String) $value->description);
- $newentry->visible = (String) $value->visible;
- $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
- if (!$newentry->id) {
- print_error('error_add_param', 'iassign');
- }
- }
- }
- }
- }
- $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
- return true;
- }
-
- public static function import_ilm ($itemid, $files_extract, $application_xml, $contextuser, $fs) {
- global $DB, $CFG, $USER, $OUTPUT;
- $description_str = str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML());
- $iassign_ilm = $DB->get_record('iassign_ilm', array("name" => (String) $application_xml->name, "version" => (String) $application_xml->version));
- if ($iassign_ilm) {
- foreach ($files_extract as $key => $value) {
- $rootfolder = $CFG->dataroot . '/temp/' . $key;
- self::delete_dir($rootfolder);
- break;
- }
- print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
- }
- else {
- $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
- if ($file_jar == null) {
- return false;
- }
- $file_jar = str_replace("./", "", $file_jar);
- if (empty($file_jar)) {
- $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In import_ilm: file_jar empty, files_extract=" . $files_extract . "<br/>\n";
- print_error($msg_error);
-
-
- }
- else {
- $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
- if (!$iassign_ilm) {
- $iassign_ilm = new stdClass();
- $iassign_ilm->id = 0;
- }
- $newentry = new stdClass();
- $newentry->name = (String) $application_xml->name;
- $newentry->version = (String) $application_xml->version;
- $newentry->type = (String) $application_xml->type;
- $newentry->url = (String) $application_xml->url;
- $newentry->description = strip_tags($description_str);
- $newentry->extension = strtolower((String) $application_xml->extension);
- $newentry->file_jar = $file_jar . "/";
- $newentry->file_class = (String) $application_xml->file_class;
- $newentry->width = (String) $application_xml->width;
- $newentry->height = (String) $application_xml->height;
- $newentry->enable = 0;
- $newentry->timemodified = time();
- $newentry->author = $USER->id;
- $newentry->timecreated = time();
- $newentry->evaluate = (String) $application_xml->evaluate;
- $newentry->reevaluate = (String) $application_xml->reevaluate;
- $newentry->parent = $iassign_ilm->id;
-
- $iassign_ilmid = $DB->insert_record("iassign_ilm", $newentry);
- if ($application_xml->params->param) {
- foreach ($application_xml->params->param as $value) {
- $newentry = new stdClass();
- $newentry->iassign_ilmid = $iassign_ilmid;
- $newentry->param_type = (String) $value->type;
- $newentry->param_name = (String) $value->name;
- $newentry->param_value = (String) $value->value;
- $newentry->description = html_entity_decode((String) $value->description);
- $newentry->visible = (String) $value->visible;
- $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
- if (!$newentry->id) {
- print_error('error_add_param', 'iassign');
- }
- }
- }
- }
- print($OUTPUT->notification(get_string('ok_import_ilm_version', 'iassign'), 'notifysuccess'));
- }
- $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
- }
-
-
-
-
-
-
- static function save_ilm_by_xml ($application_xml, $files_extract) {
- global $CFG, $USER, $OUTPUT;
- $source = "";
- $diretorio = "";
-
- if (!is_writable("ilm/")) {
- print($OUTPUT->notification(get_string('error_folder_permission_denied', 'iassign'), 'notifyproblem'));
- exit;
-
- }
-
- $application_file_name = iassign_utils::filename_from_iLM_name($application_xml->name, false);
-
- if (!file_exists("ilm/" . $application_file_name)) {
- mkdir("ilm/" . $application_file_name, 0755, true);
- touch("ilm/" . $application_file_name . DIRECTORY_SEPARATOR . "index.html");
- }
-
- if (!file_exists("ilm/" . $application_file_name . "/" . $application_xml->version)) {
- mkdir("ilm/" . $application_file_name . DIRECTORY_SEPARATOR . $application_xml->version, 0755, true);
- touch("ilm/" . $application_file_name . DIRECTORY_SEPARATOR . $application_xml->version . DIRECTORY_SEPARATOR . "index.html");
- }
- else {
- $diretorio = "./" . "ilm/" . $application_file_name . DIRECTORY_SEPARATOR . $application_xml->version;
-
- print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
-
- return $diretorio;
- }
- $root_ilm = "ilm/" . $application_file_name . "/" . $application_xml->version;
-
- foreach ($files_extract as $key => $value) {
- $file = $CFG->dataroot . '/temp/' . $key;
- if (is_dir($file)) {
- $source = $file;
- $diretorio = $root_ilm . "/" . basename($file);
-
- mkdir($diretorio, 0755, true);
- touch($diretorio . DIRECTORY_SEPARATOR . "index.html");
- break;
- }
- }
-
-
- foreach ($iterator = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
- $directory_name = $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
- if ($item->isDir()) {
- mkdir($directory_name);
- touch($directory_name . DIRECTORY_SEPARATOR . "index.html");
- }
- else {
- copy($item, $directory_name);
- }
- }
- self::delete_dir($source);
- return "./" . $diretorio;
- }
-
-
-
- public static function delete_dir ($dirPath) {
- if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
- $dirPath .= '/';
- }
- $files = glob($dirPath . '*', GLOB_MARK);
- foreach ($files as $file) {
- if (is_dir($file)) {
- self::delete_dir($file);
- }
- else {
- unlink($file);
- }
- }
- if (is_dir($dirPath))
- rmdir($dirPath);
- else
- print($OUTPUT->notification(get_string('error_file_jar_exists', 'iassign'), 'notifyproblem'));
- }
- }
- ?>
|