java.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. <?php
  2. /**
  3. * Class that implements ilm_handle, in order to allow manipulation and management of Java iLM
  4. *
  5. * @author Igor Moreira Fe'lix
  6. * @author Patricia Alves Rodrigues
  7. * @author Leo^nidas de Oliveira Branda~o
  8. * @version v 1 2017/17/10
  9. * @package mod_iassign_ilm_handlers
  10. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  11. *
  12. * <b>License</b>
  13. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  14. */
  15. global $CFG;
  16. require_once $CFG->dirroot . '/mod/iassign/ilm_handle.php';
  17. class java implements ilm_handle {
  18. /// Build HTML code to present an applet
  19. public static function build_ilm_tags ($ilm_id, $options = array()) {
  20. global $DB, $OUTPUT;
  21. global $CONF_WWW; //TODO 1 => use iLM under WWW; otherwise use under MoodleData
  22. $html = "";
  23. if (empty($options['Proposition']))
  24. $options['Proposition'] = "";
  25. if (empty($options['addresPOST']))
  26. $options['addresPOST'] = "";
  27. if (empty($options['student_answer']))
  28. $options['student_answer'] = "";
  29. if (empty($options['notSEND']))
  30. $options['notSEND'] = "";
  31. else // Case it is authoring put 'notSEND' (important to iVProgH5 to present authoring tool)
  32. if ($options['type'] == "editor_update")
  33. $options['notSEND'] = "true";
  34. if (empty($options['id_iLM_security'])) // if defined, it is from 'iassign_security'
  35. $options['id_iLM_security'] = "";
  36. $id_iLM_security = $options['id_iLM_security'];
  37. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  38. if ($iassign_ilm) {
  39. // md_files : filename
  40. $ilm_extension = $iassign_ilm->extension; // use local variavel to efficiency (several use)
  41. if ($ilm_extension) { // avoid problems
  42. $ilm_extension = strtolower($ilm_extension);
  43. }
  44. // Attention: in iAssign 2014 on, all the iLM is located on the Moodle filesystem (usually /var/moodledata/filedir/).
  45. // This means that '$iassign_ilm->file_jar' = '*_files.id'
  46. /*$file_url = array();
  47. $fs = get_file_storage();
  48. $files_jar = explode(",", $iassign_ilm->file_jar);
  49. foreach ($files_jar as $one_file) {
  50. $file = $fs->get_file_by_id($one_file);
  51. if (!$file)
  52. print $OUTPUT->notification(get_string('error_confirms_jar', 'iassign'), 'notifyproblem');
  53. else {
  54. // Get file path (informatin on Moodle table '*_files' - in its field 'contenthash'
  55. // The actual file is under the Moodle data. E.g., if Moodle data is the default '/var/moodledata' and 'contenthash="5641c1a0e1f5b37fa0b74996ead592c77ff027bc"',
  56. // then the JAR file in: '/var/moodledata/fildir/56/41/5641c1a0e1f5b37fa0b74996ead592c77ff027bc'
  57. $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
  58. array_push($file_url, $url);
  59. }
  60. }*/
  61. $lang = substr(current_language(), 0, 2);
  62. if ($options['type'] == "filter") { //leo
  63. $iassign_ilm_width = $options['width']; // or use? $iassign_ilm->width
  64. $iassign_ilm_height = $options['height']; // or use? $iassign_ilm->height
  65. } else { //leo
  66. $iassign_ilm_width = $iassign_ilm->width;
  67. $iassign_ilm_height = $iassign_ilm->height; // or use? $iassign_ilm->height
  68. }
  69. $file_url = explode(",", $iassign_ilm->file_jar);
  70. if (!empty($file_url)) { // There is an iLM file
  71. // Build tag to JAR file
  72. $html .= ' <!-- iAssign - view iLM content / LInE - http://line.ime.usp.br -->' . "\n";
  73. $html .= ' <applet id="iLM_applet" name="iLM" archive="' . new moodle_url("/mod/iassign/". implode(",", $file_url)) . '" code="' . $iassign_ilm->file_class . '" width="' . $iassign_ilm_width . '" height="' . $iassign_ilm_height . '" vspace=10 hspace=10>' . "\n";
  74. $html .= ' <param name="lang" value="' . $lang . '"/>' . "\n";
  75. switch ($options['type']) {
  76. case "view":
  77. $html .= ' <!-- view -->' . "\n";
  78. $html .= ' <param name="iLM_PARAM_SendAnswer" value="' . $options['notSEND'] . '"/>' . "\n"; // ATTENTION: MA_PARAM_notSEND=true => iLM_PARAM_SendAnswer=false
  79. $html .= ' <param name="MA_PARAM_notSEND" value="true"/>' . "\n"; // iLM version 1.0
  80. //MOOC 2016 --- allow to load dynamic parameters
  81. //TODO: REVIEW: this code is to insert iLM as HTML5 and to allow general parameter to any iLM
  82. //n $iassign_ilm_config = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_id));
  83. //n foreach ($iassign_ilm_config as $ilm_config) {
  84. //n if (array_key_exists($ilm_config->param_name, $options)) {
  85. //n $ilm_config->param_value = $options[$ilm_config->param_name];
  86. //n $html .= ' <param name="' . $ilm_config->param_name . '" value="' . $ilm_config->param_value . '"/>' . "\n";
  87. //n }
  88. //n }
  89. break;
  90. case "activity":
  91. $html .= ' <!-- activity -->' . "\n";
  92. $html .= ' <param name="iLM_PARAM_Assignment" value="' . $options['Proposition'] . '"/>' . "\n"; // iLM version 2.0
  93. $html .= ' <param name="iLM_PARAM_SendAnswer" value="' . $options['notSEND'] . '"/>' . "\n"; // ATTENTION: MA_PARAM_notSEND=true => iLM_PARAM_SendAnswer=false
  94. $html .= ' <param name="iLM_PARAM_ServerToGetAnswerURL" value="' . $options['addresPOST'] . '"/>' . "\n"; // not necessary in version iLM 2.0
  95. $html .= ' <param name="MA_PARAM_PropositionURL" value="true"/>' . "\n";
  96. $html .= ' <param name="MA_PARAM_Proposition" value="' . $options['Proposition'] . '"/>' . "\n"; // in iLM 2.0 is in 'iLM_PARAM_Assignment' already
  97. $html .= ' <param name="MA_PARAM_notSEND" value="' . $options['notSEND'] . '"/>' . "\n";
  98. $html .= ' <param name="MA_PARAM_addresPOST" value="' . $options['addresPOST'] . '"/>' . "\n"; // not necessary in version iLM 2.0
  99. if ($options['special_param'] == 1) {
  100. $html .= '<param name="TIPO_SCRIPT" value="1"/>' . "\n";
  101. $html .= '<param name="BOTAOSCR1" value="' . $options['student_answer'] . '" />' . "\n";
  102. }
  103. //MOOC 2016 --- allow to load dynamic parameters
  104. //n $iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $options['iassign_statement']));
  105. //n if ($iassign_activity_item_configs) {
  106. //n foreach ($iassign_activity_item_configs as $iassign_activity_item_config)
  107. //n $html .= ' <param name="'.$iassign_activity_item_config->param_name.'" value="'.$iassign_activity_item_config->param_value.'"/>' . "\n";
  108. //n }
  109. break;
  110. case "editor_new":
  111. $html .= ' <!-- editor_new -->' . "\n";
  112. $html .= ' <param name="iLM_PARAM_Assignment" value="' . $options['Proposition'] . '"/>' . "\n"; // iLM version 2.0
  113. $html .= ' <param name="iLM_PARAM_SendAnswer" value="' . $options['notSEND'] . '"/>' . "\n"; // ATTENTION: MA_PARAM_notSEND=true => iLM_PARAM_SendAnswer=false
  114. $html .= ' <param name="iLM_PARAM_Authoring" value="true"/>' . "\n";
  115. $html .= ' <param name="MA_PARAM_PropositionURL" value="true"/>' . "\n"; // iLM version 1.0
  116. $html .= ' <param name="MA_PARAM_notSEND" value="' . $options['notSEND'] . '"/>' . "\n";
  117. $html .= ' <param name="MA_PARAM_ArchiveTeacher" value="true"/>' . "\n";
  118. break;
  119. case "editor_update":
  120. $html .= ' <!-- editor_update -->' . "\n";
  121. $html .= ' <param name="iLM_PARAM_Assignment" value="' . $options['Proposition'] . '"/>' . "\n"; // iLM version 2.0
  122. $html .= ' <param name="iLM_PARAM_Authoring" value="true"/>' . "\n";
  123. $html .= ' <param name="iLM_PARAM_SendAnswer" value="' . $options['notSEND'] . '"/>' . "\n"; // ATTENTION: MA_PARAM_notSEND=true => iLM_PARAM_SendAnswer=false
  124. $html .= ' <param name="MA_PARAM_PropositionURL" value="true"/>' . "\n"; // iLM version 1.0
  125. $html .= ' <param name="MA_PARAM_Proposition" value="' . $options['Proposition'] . '"/>' . "\n";
  126. $html .= ' <param name="MA_PARAM_ArchiveTeacher" value="true"/>' . "\n";
  127. $html .= ' <param name="MA_PARAM_notSEND" value="' . $options['notSEND'] . '"/>' . "\n";
  128. break;
  129. default:
  130. print_error('error_view_without_actiontype', 'iassign'); //
  131. }
  132. $html .= '</applet> <br/>' . "\n";
  133. } // if (!empty($file_url))
  134. } // if ($iassign_ilm)
  135. $verify_java = '
  136. <script>var hasJava= navigator.javaEnabled();
  137. if (!hasJava) {
  138. var tableRef = document.getElementById("outlinetable").getElementsByTagName("tbody")[0];
  139. var newRow = tableRef.insertRow();
  140. var newCell = newRow.insertCell(0);
  141. newCell.style.textAlign = "center";
  142. newCell.style.border = "2px solid red";
  143. newCell.style.background = "#ffe8e8";
  144. newCell.style.fontSize = "1.5em";
  145. var newText = document.createTextNode("'.get_string('applet_blocked', 'iassign').'");
  146. newCell.appendChild(newText);
  147. }
  148. </script>'; // '
  149. return $verify_java . $html;
  150. }
  151. /// Presents an activity with its iLM
  152. public static function show_activity_in_ilm ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  153. global $USER, $CFG, $DB;
  154. $ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  155. // enderecoPOST: eliminei a tag '&write_solution=0' deixando para este 'view' completar, eventualmente com '&write_solution=1'!
  156. $special_param1 = $iassign_statement_activity_item->special_param1;
  157. $context = context_module::instance($USER->cm);
  158. //TODO Given an activity => find its correspondent file in Moodle data. Bad solution!
  159. //TODO Change the meaning of 'iassign_statement.file' from insertion order to the ID in table 'files'.
  160. //TODO This demands update to each 'iassign_statement', find its corresponding on in 'files', and update 'iassign_statement.file = files.id'
  161. if ($view_teacherfileversion) { // get the exercise in Moodle data (teacher file)
  162. $fileid = "";
  163. $fs = get_file_storage();
  164. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file); // iassign_statement_activity_item = table 'iassign_statement'
  165. if ($files) {
  166. foreach ($files as $value) {
  167. if ($value->get_filename() != '.')
  168. $fileid = $value->get_id();
  169. }
  170. }
  171. if (!$fileid) { // 'Something is wrong. Maybe your teacher withdrew this exercise file. Please, inform your teacher.';
  172. print iassign::warning_message_iassign('error_exercise_removed') . "<br/>\n"; // I couldn't find the file in table 'files'!
  173. }
  174. }
  175. $ilm_name = strtolower($ilm->name);
  176. $extension = iassign_utils::filename_extension($ilm_name);
  177. if ($ilm_name == "igeom") { // is iGeom exercise
  178. $is_igeom = true;
  179. if (isset($fileid))
  180. $content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
  181. if ($special_param1 == 1 && !empty($student_answer) && (!$view_teacherfileversion)) { // is script
  182. $view_teacherfileversion = true; // here when student is doing/redoing his activity
  183. }
  184. elseif (!$view_teacherfileversion) { // Student seem his solution or teacher seem it (of one student)
  185. $content_or_id_from_ilm_security = $student_answer;
  186. }
  187. else //TODO 2021/02 $fileid is used?
  188. $content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
  189. }
  190. else {
  191. if ($view_teacherfileversion) { // $view_teacherfileversion==1 => load the exercise ('activity') from the 'moodledata' (id in 'files')
  192. // $content_or_id_from_ilm_security = $this->context->id;
  193. $content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
  194. }
  195. else { // $view_teacherfileversion==null => load the learner answer from the data base (iassign_submission)
  196. $content_or_id_from_ilm_security = $student_answer;
  197. }
  198. }
  199. $allow_submission = false; // There is permission to 'submission' button?
  200. if ($USER->iassignEdit == 1 && $student_answer) { // for now, only iVProg2 and iVProgH5 allows editions of exercise already sent
  201. $allow_submission = true; // yes!
  202. $write_solution = 1;
  203. $enderecoPOST .= "&write_solution=1"; // complement POST address indicating that the learner could send edited solution
  204. }
  205. // Security: this avoid the student get a second access to the file content (usually an exercise)
  206. // Data are registered in the table '*_iassign_security' bellow and is erased by function 'view()' above.
  207. // IMPORTANT: the '$end_file' will receive the iLM content URL using the security filter './mod/iassign/ilm_security.php'
  208. // the iLM must request the content using this URL. Data are registered in the table '*_iassign_security'.
  209. // Attention : using iVProgH5 there are lot of " and the use of slashes (as '\"') will imply in iVProgH5 do not read the file!
  210. // do not use: $id_iLM_security = $this->write_iLM_security($iassign_statement_activity_item->id, addslashes($content_or_id_from_ilm_security));
  211. //2017 $id_iLM_security = $this->write_iLM_security($iassign_statement_activity_item->id, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  212. //2017 $this->remove_old_iLM_security_entries($USER->id, $iassign_statement_activity_item->id); // additional security: erase eventually old entries
  213. require_once ($CFG->dirroot . '/mod/iassign/ilm_security.php');
  214. $timecreated = time();
  215. $token = md5($timecreated); // iassign_iLM_security->timecreated);
  216. // Try to get the student answer
  217. // In './ilm_security.php': write_iLM_security($userid, $timecreated, $iassign_statementid = -1, $content_or_id_from_ilm_security)
  218. $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'
  219. // $iassign_iLM_security = $DB->get_record("iassign_security", array("id" => $id_iLM_security));
  220. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $id_iLM_security . '&token=' . $token . '&view=' . $view_teacherfileversion; // need full path...
  221. //TODO iLM_HTML5 :: Need to use '*_iassign_ilm.ilm_type' in { 'jar', 'html5' }
  222. //TODO iLM_HTML5 :: For now I use the particular case of
  223. //leo Ou usar: if ($extension == "html" || $extension == "ivph") // if iLM is HTML5 is inside a frame
  224. $iassign = "
  225. <script type='text/javascript'>
  226. //<![CDATA[
  227. function jsAnalyseAnswer () {
  228. var strAnswer = document.applets[0].getAnswer(); //leo estava comentado!
  229. var evaluationResult = document.applets[0].getEvaluation(); //leo estava comentado!
  230. var comment = document.formEnvio.submission_comment.value;
  231. if ((strAnswer==null || strAnswer=='' || strAnswer==-1) && (comment==null || comment=='')) { // undefined
  232. alert('" . get_string('activity_empty', 'iassign') . "');
  233. return false; // success
  234. }
  235. else {
  236. document.formEnvio.iLM_PARAM_ArchiveContent.value = strAnswer;
  237. document.formEnvio.iLM_PARAM_ActivityEvaluation.value = evaluationResult;
  238. document.formEnvio.submit();
  239. return true; // any error...
  240. }
  241. }
  242. //]]>
  243. </script>\n"; //
  244. $iassign .= "\n<center>\n<form name='formEnvio' id='formEnvio' method='post' action='$enderecoPOST' enctype='multipart/form-data'>\n";
  245. // Attention: The actual iLM content will be provided by the indirect access in './mod/iassign/ilm_security.php',
  246. // bellow only the 'token' to the content will be shown in URL (by security reason). The iLM must use this URL on
  247. // 'MA_PARAM_Proposition' to request the content.
  248. // Calls static function bellow: parameters are data to store in table '*_iassign_submission'
  249. //leo $iassign .= ilm_settings::build_ilm_tags($this->ilm->id, array(
  250. $iassign .= ilm_settings::build_ilm_tags($ilm->id, array(//leo para testar 'iassign_security'
  251. "type" => "activity",
  252. "notSEND" => "false",
  253. "addresPOST" => $enderecoPOST,
  254. "Proposition" => $end_file,
  255. "special_param" => $special_param1,
  256. "student_answer" => $student_answer,
  257. "id_iLM_security" => $id_iLM_security,
  258. "iassign_statement" => $iassign_statement_activity_item->id // MOOC 2016
  259. ));
  260. if (!isguestuser() && $iassign_statement_activity_item->type_iassign != 1
  261. && ($ilm->editingbehavior == 1 || ($ilm->editingbehavior == 0 && !in_array($_GET['action'], array('viewsubmission', 'view'))))) {
  262. $iassign .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>\n";
  263. $iassign .= " <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>\n";
  264. if (!has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  265. $iassign .= " <p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  266. else
  267. $iassign .= " <input type='hidden' name='submission_comment'>\n";
  268. if ($allow_submission) { // it is not iGeom
  269. $iassign .= "<center>\n<!-- load button -->\n" .
  270. " <input type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
  271. get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
  272. } else {
  273. // Works with 'javascript:window.jsAnalyseAnswer()' or simply 'jsAnalyseAnswer()'
  274. $iassign .= "<center>\n<!-- load button -->\n" .
  275. " <input type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
  276. get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
  277. }
  278. } // if (!isguestuser() && $iassign_statement_activity_item->type_iassign != 1)
  279. elseif ($ilm->editingbehavior == 0) {
  280. $iassign .= "<center><br><a href=\"view.php?action=repeat&id=".$_GET['id']
  281. ."&iassign_current=".$_GET['iassign_current']."\">
  282. <input type='button' value='".get_string('repeat', 'iassign')."'></a></center>";
  283. }
  284. $iassign .= "</form></center>\n\n";
  285. return $iassign;
  286. }
  287. /**
  288. * Exibe os dados de um iLM
  289. */
  290. public static function view_ilm($ilmid, $from) {
  291. global $DB;
  292. $url = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
  293. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  294. $str = "";
  295. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  296. $str .= '<tr>';
  297. $str .= '<td colspan=3 align=right>';
  298. if ($from != 'admin') {
  299. $str .= '<input type=button value="' . get_string('return', 'iassign') . '" onclick="javascript:window.location = \'' . $_SERVER['HTTP_REFERER'] . '\';">' . "\n";
  300. }
  301. $str .= '<input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close();">';
  302. $str .= '</td>' . "\n";
  303. $str .= '</tr>' . "\n";
  304. if ($iassign_ilm) {
  305. $iassign_statement_activity_item = $DB->get_records('iassign_statement', array("iassign_ilmid" => $iassign_ilm->id));
  306. if ($iassign_statement_activity_item) {
  307. $total = count($iassign_statement_activity_item);
  308. } else {
  309. $total = 0;
  310. }
  311. if ($from == 'admin') {
  312. $str .= '<tr><td colspan=2>' . "\n";
  313. $str .= '<table width="100%" class="generaltable boxaligncenter" >' . "\n";
  314. $str .= '<tr>' . "\n";
  315. $str .= '<td class=\'cell c0 actvity\' ><strong>' . get_string('activities', 'iassign') . ':</strong>&nbsp;' . $total . '</td>' . "\n";
  316. $str .= '<td><strong>' . get_string('url_ilm', 'iassign') . '</strong>&nbsp;<a href="' . $iassign_ilm->url . '">' . $iassign_ilm->url . '</a></td>' . "\n";
  317. $str .= '</tr>' . "\n";
  318. $str .= '<tr><td colspan=2><strong>' . get_string('description', 'iassign') . ':</strong>&nbsp;' . iassign_language::get_description_lang(current_language(), $iassign_ilm->description) . '</td></tr>' . "\n";
  319. $str .= '<tr><td width="50%"><strong>' . get_string('type_ilm', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->type . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>' . get_string('extension', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->extension . '</td>' . "\n";
  320. $str .= '<td width="50%"><strong>' . get_string('width', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->width;
  321. $str .= '&nbsp;&nbsp;<strong>' . get_string('height', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->height . '</td></tr>' . "\n";
  322. $str .= '<tr><td><strong>' . get_string('file_jar', 'iassign') . ':</strong>&nbsp;' . basename($iassign_ilm->file_jar) . '</td>' . "\n";
  323. $str .= '<td ><strong>' . get_string('file_class', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->file_class . '</td></tr>' . "\n";
  324. if ($iassign_ilm->evaluate == 1) {
  325. $evaluate = get_string('yes', 'iassign');
  326. } else {
  327. $evaluate = get_string('no', 'iassign');
  328. }
  329. $str .= '<tr><td width="50%"><strong>' . get_string('evaluate', 'iassign') . ':</strong>&nbsp;' . $evaluate . '</td>' . "\n";
  330. if ($iassign_ilm->enable == 1) {
  331. $enable = get_string('yes', 'iassign');
  332. } else {
  333. $enable = get_string('no', 'iassign');
  334. }
  335. $str .= '<td width="50%"><strong>' . get_string('enable', 'iassign') . ':</strong>&nbsp;' . $enable . '</td></tr>' . "\n";
  336. $str .= '<tr>' . "\n";
  337. $str .= '<td width="50%"><strong>' . get_string('file_created', 'iassign') . ':</strong>&nbsp;' . userdate($iassign_ilm->timecreated) . '</td>' . "\n";
  338. $str .= '<td width="50%"><strong>' . get_string('file_modified', 'iassign') . ':</strong>&nbsp;' . userdate($iassign_ilm->timemodified) . '</td>' . "\n";
  339. $str .= '</tr>' . "\n";
  340. $user_ilm = $DB->get_record('user', array('id' => $iassign_ilm->author));
  341. if ($user_ilm) {
  342. $str .= '<tr>' . "\n";
  343. $str .= '<td colspan=2><strong>' . get_string('author', 'iassign') . ':</strong>&nbsp;' . $user_ilm->firstname . '&nbsp;' . $user_ilm->lastname . '</td>' . "\n";
  344. $str .= '</tr>' . "\n";
  345. }
  346. $str .= '</table>' . "\n";
  347. $str .= '</td></tr>' . "\n";
  348. }
  349. if (!empty($iassign_ilm->file_jar)) {
  350. //TODO: REVIEW: to be used for parameters of "applet" from DB
  351. $options = array("type" => "view"); //MOOC2014: start
  352. $str .= '<tr class=\'cell c0 actvity\'><td colspan=3 align=center bgcolor="#F5F5F5">' . "\n";
  353. // Second parameter null since 'iassign_security' are not define yet
  354. $str .= ilm_settings::build_ilm_tags($iassign_ilm->id, $options);
  355. //TODO: REVIEW: missing code to manage parameters
  356. //MOOC2014: tem este codigo!
  357. } else {
  358. $str .= '<tr class=\'cell c0 actvity\'>' . "\n";
  359. $str .= '<td colspan=2 align=center>' . get_string('null_file', 'iassign') . '</td>' . "\n";
  360. $str .= '<td align=center><a href="' . $url . '</a></td>' . "\n";
  361. $str .= '</tr>' . "\n";
  362. }
  363. $str .= '</td></tr>' . "\n";
  364. }
  365. $str .= '</table>' . "\n";
  366. return $str;
  367. }
  368. /**
  369. * Copia ou gera uma nova versão do iLM
  370. */
  371. public static function copy_new_version_ilm($param, $files_extract) {
  372. global $DB, $CFG;
  373. $iassign_ilm = new stdClass();
  374. $iassign_ilm->name = $param->name;
  375. $iassign_ilm->version = $param->version;
  376. $iassign_ilm->file_jar = null;
  377. $file_jar = null;
  378. if (!is_null($files_extract)) {
  379. foreach ($files_extract as $key => $value) {
  380. if (strpos(strtolower($key), ".jar")) {
  381. $extract = new stdClass();
  382. $extract->file_jar = $key;
  383. $extract->name = $param->name;
  384. $extract->version = $param->version;
  385. echo $key;
  386. $file_jar = self::save_ilm_by_xml($extract, $files_extract)[0];
  387. echo $file_jar;
  388. break;
  389. }
  390. }
  391. }
  392. $description = json_decode($param->description_lang);
  393. $description->{$param->set_lang} = $param->description;
  394. $newentry = new stdClass();
  395. $newentry->name = $param->name;
  396. $newentry->version = $param->version;
  397. $newentry->type = "Java";
  398. $newentry->url = $param->url;
  399. $newentry->description = strip_tags(json_encode($description));
  400. $newentry->extension = strtolower($param->extension);
  401. if (!is_null($file_jar)) {
  402. $newentry->file_jar = $file_jar;
  403. }
  404. $newentry->file_class = $param->file_class;
  405. $newentry->width = $param->width;
  406. $newentry->height = $param->height;
  407. $newentry->enable = 0;
  408. $newentry->timemodified = $param->timemodified;
  409. $newentry->timecreated = $param->timecreated;
  410. $newentry->evaluate = $param->evaluate;
  411. $newentry->author = $param->author;
  412. $newentry->parent = $param->parent;
  413. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  414. // log event --------------------------------------------------------------------------------------
  415. iassign_log::add_log('copy_iassign_ilm', 'name: ' . $param->name . ' ' . $param->version, 0, $newentry->id);
  416. // log event --------------------------------------------------------------------------------------
  417. }
  418. /// Export an iLM to a package of the iLM (with its descriptor XML)
  419. public static function export_ilm ($ilm_id) {
  420. global $DB, $CFG;
  421. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  422. $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_id)); //MOOC 2016
  423. $files_jar = str_replace(basename($iassign_ilm->file_jar), "", $iassign_ilm->file_jar);
  424. $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '_' . date("Ymd-Hi") . '.ipz';
  425. $zip = new zip_archive();
  426. $zip->open($zip_filename);
  427. $rootdir = $CFG->dirroot . '/mod/iassign/' . $files_jar;
  428. $allfiles = self::list_directory($rootdir);
  429. $i = 0;
  430. $base_jar = "";
  431. foreach ($allfiles as $file) {
  432. $mini = basename(str_replace($CFG->dirroot . '/mod/iassign/ilm/', "", $file));
  433. if (!is_dir($file)) {
  434. $zip->add_file_from_pathname($mini, $file);
  435. $base_jar = $mini;
  436. }
  437. }
  438. $application_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  439. $application_descriptor .= '<application xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  440. $application_descriptor .= ' <name>' . $iassign_ilm->name . '</name>' . "\n";
  441. $application_descriptor .= ' <url>' . $iassign_ilm->url . '</url>' . "\n";
  442. $application_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  443. $application_descriptor .= ' <type>' . $iassign_ilm->type . '</type>' . "\n";
  444. $application_descriptor .= ' <description>' . html_entity_decode(str_replace(array('<p>', '</p>'), array('', ''), $iassign_ilm->description)) . '</description>' . "\n";
  445. $application_descriptor .= ' <extension>' . $iassign_ilm->extension . '</extension>' . "\n";
  446. $application_descriptor .= ' <file_jar>' . $base_jar . '</file_jar>' . "\n";
  447. $application_descriptor .= ' <file_class>' . $iassign_ilm->file_class . '</file_class>' . "\n";
  448. $application_descriptor .= ' <width>' . $iassign_ilm->width . '</width>' . "\n";
  449. $application_descriptor .= ' <height>' . $iassign_ilm->height . '</height>' . "\n";
  450. $application_descriptor .= ' <evaluate>' . $iassign_ilm->evaluate . '</evaluate>' . "\n";
  451. if ($iassign_ilm_configs) { //MOOC 2016
  452. $application_descriptor .= ' <params>' . "\n";
  453. foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  454. $application_descriptor .= ' <param>' . "\n";
  455. $application_descriptor .= ' <type>' . $iassign_ilm_config->param_type . '</type>' . "\n";
  456. $application_descriptor .= ' <name>' . $iassign_ilm_config->param_name . '</name>' . "\n";
  457. $application_descriptor .= ' <value>' . $iassign_ilm_config->param_value . '</value>' . "\n";
  458. $application_descriptor .= ' <description>' . htmlentities(str_replace("\n", "", $iassign_ilm_config->description)) . '</description>' . "\n";
  459. $application_descriptor .= ' <visible>' . $iassign_ilm_config->visible . '</visible>' . "\n";
  460. $application_descriptor .= ' </param>' . "\n";
  461. }
  462. $application_descriptor .= ' </params>' . "\n";
  463. } //MOOC 2016
  464. $application_descriptor .= '</application>' . "\n";
  465. $zip->add_file_from_string('ilm-application.xml', $application_descriptor);
  466. $zip->close();
  467. header("Pragma: public");
  468. header("Expires: 0");
  469. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  470. header("Cache-Control: private", false);
  471. header("Content-Type: application/zip");
  472. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  473. header("Content-Transfer-Encoding: binary");
  474. header("Content-Length: " . @filesize($zip_filename));
  475. set_time_limit(0);
  476. @readfile("$zip_filename") || die("File not found.");
  477. unlink($zip_filename);
  478. exit;
  479. }
  480. public static function delete_ilm($ilm_id) {
  481. global $DB, $CFG, $OUTPUT;
  482. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  483. // Prepare the path of directory to be removed
  484. $path_w = rtrim($iassign_ilm->file_jar, "/");
  485. $folder_to_remove = substr($path_w, 0, strrpos($path_w, '/') + 1);
  486. // Check if the iLM directory is writable
  487. if (!is_writable($iassign_ilm->file_jar)) {
  488. return null;
  489. }
  490. self::delete_dir($folder_to_remove);
  491. $ilm_folder = "ilm/" . $iassign_ilm->name . "/";
  492. $k = 0;
  493. // Verify if iLM parent directory is empty, if yes, remove it
  494. foreach(glob($ilm_folder . "*", GLOB_ONLYDIR) as $dir) {
  495. $k ++;
  496. break;
  497. }
  498. if ($k == 0) {
  499. self::delete_dir($ilm_folder);
  500. }
  501. $DB->delete_records("iassign_ilm", array('id' => $ilm_id));
  502. $DB->delete_records("iassign_ilm_config", array('iassign_ilmid' => $ilm_id)); //MOOC 2016
  503. // log event --------------------------------------------------------------------------------------
  504. iassign_log::add_log('delete_iassign_ilm', 'name: ' . $iassign_ilm->name . ' ' . $iassign_ilm->version, 0, $iassign_ilm->id);
  505. // log event --------------------------------------------------------------------------------------
  506. return $iassign_ilm->parent;
  507. }
  508. /*public static function delete_ilm($ilm_id) {
  509. global $DB, $CFG;
  510. $fs = get_file_storage();
  511. $contextsystem = context_system::instance();
  512. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  513. $files_jar = explode(",", $iassign_ilm->file_jar);
  514. foreach ($files_jar as $file_jar) {
  515. $file = $fs->get_file_by_id($file_jar);
  516. if ($file)
  517. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  518. }
  519. $DB->delete_records("iassign_ilm", array('id' => $ilm_id));
  520. $DB->delete_records("iassign_ilm_config", array('iassign_ilmid' => $ilm_id)); //MOOC 2016
  521. // log event --------------------------------------------------------------------------------------
  522. iassign_log::add_log('delete_iassign_ilm', 'name: ' . $iassign_ilm->name . ' ' . $iassign_ilm->version, 0, $iassign_ilm->id);
  523. // log event --------------------------------------------------------------------------------------
  524. return $iassign_ilm->parent;
  525. }*/
  526. /// Register data from an iLM after to updated it
  527. public static function edit_ilm ($param, $itemid, $files_extract, $contextuser) {
  528. global $DB, $CFG;
  529. $iassign_ilm = new stdClass();
  530. $iassign_ilm->name = $param->name;
  531. $iassign_ilm->version = $param->version;
  532. $iassign_ilm->file_jar = $param->file_jar;
  533. $file_jar = null;
  534. if (!is_null($files_extract)) {
  535. foreach ($files_extract as $key => $value) {
  536. if (strpos(strtolower($key), ".jar")) {
  537. $extract = new stdClass();
  538. $extract->file_jar = $key;
  539. $extract->name = $param->name;
  540. $extract->version = $param->version;
  541. echo $key;
  542. $file_jar = self::save_ilm_by_xml($extract, $files_extract)[0];
  543. echo $file_jar;
  544. break;
  545. }
  546. }
  547. }
  548. $description = json_decode($param->description_lang);
  549. $description->{$param->set_lang} = $param->description;
  550. $updentry = new stdClass();
  551. $updentry->id = $param->id;
  552. $updentry->version = $param->version;
  553. $updentry->url = $param->url;
  554. $updentry->description = strip_tags(json_encode($description));
  555. $updentry->extension = strtolower($param->extension);
  556. if (!is_null($file_jar)) {
  557. $updentry->file_jar = $file_jar;
  558. }
  559. $updentry->file_class = $param->file_class;
  560. $updentry->width = $param->width;
  561. $updentry->height = $param->height;
  562. $updentry->enable = $param->enable;
  563. $updentry->timemodified = $param->timemodified;
  564. $updentry->evaluate = $param->evaluate;
  565. $DB->update_record("iassign_ilm", $updentry);
  566. // log event --------------------------------------------------------------------------------------
  567. iassign_log::add_log('update_iassign_ilm', 'name: ' . $param->name . ' ' . $param->version, 0, $param->id);
  568. // log event --------------------------------------------------------------------------------------
  569. }
  570. /**
  571. * Realiza os procedimentos relacionados ao armazenamento dos dados do iLM e seus arquivos
  572. */
  573. public static function new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs) {
  574. global $DB, $CFG, $USER, $OUTPUT;
  575. $description_str = str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML());
  576. $iassign_ilm = $DB->get_record('iassign_ilm', array("name" => (String) $application_xml->name, "version" => (String) $application_xml->version));
  577. if ($iassign_ilm) {
  578. foreach ($files_extract as $key => $value) {
  579. $file = $CFG->dataroot . '/temp/' . $key;
  580. if (file_exists($file))
  581. unlink($file);
  582. }
  583. print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
  584. } else {
  585. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  586. if (empty($file_jar))
  587. print_error('error_add_ilm', 'iassign');
  588. else { // if (empty($file_jar))
  589. $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
  590. if (!$iassign_ilm) {
  591. $iassign_ilm = new stdClass(); //MOOC 2016
  592. $iassign_ilm->id = 0;
  593. }
  594. $newentry = new stdClass();
  595. $newentry->name = (String) $application_xml->name;
  596. $newentry->version = (String) $application_xml->version;
  597. $newentry->type = (String) $application_xml->type;
  598. $newentry->url = (String) $application_xml->url;
  599. $newentry->description = strip_tags($description_str);
  600. $newentry->extension = strtolower((String) $application_xml->extension);
  601. $newentry->file_jar = $file_jar;
  602. $newentry->file_class = (String) $application_xml->file_class;
  603. $newentry->width = (String) $application_xml->width;
  604. $newentry->height = (String) $application_xml->height;
  605. $newentry->enable = 0;
  606. $newentry->timemodified = time();
  607. $newentry->author = $USER->id;
  608. $newentry->timecreated = time();
  609. $newentry->evaluate = (String) $application_xml->evaluate;
  610. $newentry->parent = $iassign_ilm->id;
  611. //MOOC 2016 $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  612. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  613. // log event --------------------------------------------------------------------------------------
  614. iassign_log::add_log('add_iassign_ilm', 'name: ' . $application_xml->name . ' ' . $application_xml->version, 0, $newentry->id);
  615. // log event --------------------------------------------------------------------------------------
  616. if ($application_xml->params->param) {
  617. foreach ($application_xml->params->param as $value) {
  618. $newentry = new stdClass();
  619. $newentry->iassign_ilmid = $iassign_ilmid;
  620. $newentry->param_type = (String) $value->type;
  621. $newentry->param_name = (String) $value->name;
  622. $newentry->param_value = (String) $value->value;
  623. $newentry->description = html_entity_decode((String) $value->description);
  624. $newentry->visible = (String) $value->visible;
  625. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  626. if (!$newentry->id) {
  627. print_error('error_add_param', 'iassign');
  628. }
  629. }
  630. }
  631. }
  632. }
  633. $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  634. return true;
  635. }
  636. /**
  637. * Realiza os procedimentos relacionados ao armazenamento de um iLM por meio da importação
  638. */
  639. public static function import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs) {
  640. global $DB, $CFG, $USER, $OUTPUT;
  641. $description_str = str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML());
  642. $iassign_ilm = $DB->get_record('iassign_ilm', array("name" => (String) $application_xml->name, "version" => (String) $application_xml->version));
  643. if ($iassign_ilm) {
  644. foreach ($files_extract as $key => $value) {
  645. $file = $CFG->dataroot . '/temp/' . $key;
  646. if (file_exists($file))
  647. unlink($file);
  648. }
  649. print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
  650. } else {
  651. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  652. if (empty($file_jar))
  653. print_error('error_add_ilm', 'iassign');
  654. else { // if (empty($file_jar))
  655. $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
  656. if (!$iassign_ilm) {
  657. $iassign_ilm = new stdClass(); //MOOC 2016
  658. $iassign_ilm->id = 0;
  659. }
  660. $newentry = new stdClass();
  661. $newentry->name = (String) $application_xml->name;
  662. $newentry->version = (String) $application_xml->version;
  663. $newentry->type = (String) $application_xml->type;
  664. $newentry->url = (String) $application_xml->url;
  665. $newentry->description = strip_tags($description_str);
  666. $newentry->extension = strtolower((String) $application_xml->extension);
  667. $newentry->file_jar = implode(",", $file_jar);
  668. $newentry->file_class = (String) $application_xml->file_class;
  669. $newentry->width = (String) $application_xml->width;
  670. $newentry->height = (String) $application_xml->height;
  671. $newentry->enable = 0;
  672. $newentry->timemodified = time();
  673. $newentry->author = $USER->id;
  674. $newentry->timecreated = time();
  675. $newentry->evaluate = (String) $application_xml->evaluate;
  676. $newentry->parent = $iassign_ilm->id;
  677. //MOOC 2016 $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  678. $iassign_ilmid = $DB->insert_record("iassign_ilm", $newentry);
  679. if ($application_xml->params->param) {
  680. foreach ($application_xml->params->param as $value) {
  681. $newentry = new stdClass();
  682. $newentry->iassign_ilmid = $iassign_ilmid;
  683. $newentry->param_type = (String) $value->type;
  684. $newentry->param_name = (String) $value->name;
  685. $newentry->param_value = (String) $value->value;
  686. $newentry->description = html_entity_decode((String) $value->description);
  687. $newentry->visible = (String) $value->visible;
  688. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  689. if (!$newentry->id) {
  690. print_error('error_add_param', 'iassign');
  691. }
  692. }
  693. }
  694. }
  695. print($OUTPUT->notification(get_string('ok_import_ilm_version', 'iassign'), 'notifysuccess'));
  696. } // else if ($iassign_ilm)
  697. $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  698. }
  699. /// Function for save iLM from XML descriptor
  700. // @param array $application_xml Data of XML descriptor
  701. // @param array $files_extract Filenames of extract files
  702. // @return array Return an array content id of JAR files
  703. static function save_ilm_by_xml($application_xml, $files_extract) {
  704. global $CFG, $USER, $OUTPUT;
  705. // Check if the iLM directory is writable
  706. if (!is_writable("ilm/")) {
  707. print($OUTPUT->notification(get_string('error_folder_permission_denied', 'iassign'), 'notifyproblem'));
  708. return null;
  709. }
  710. // Check if iLM directory already exists
  711. if (!file_exists("ilm/" . $application_xml->name)) {
  712. // mkdir("ilm/" . $application_xml->name, 0777, true);
  713. mkdir("ilm/" . $application_xml->name, 0755, true); // permissions: drwxr-xr-x
  714. }
  715. // Check if iLM version already exists in directory
  716. if (!file_exists("ilm/" . $application_xml->name . "/" . $application_xml->version)) {
  717. // mkdir("ilm/" . $application_xml->name . "/" . $application_xml->version, 0777, true);
  718. mkdir("ilm/" . $application_xml->name . "/" . $application_xml->version, 0755, true); // drwxr-xr-x
  719. }
  720. else {
  721. print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
  722. return null;
  723. }
  724. $root_ilm = "ilm/" . $application_xml->name . "/" . $application_xml->version;
  725. // Extract iLM files to directory
  726. foreach ($files_extract as $key => $value) {
  727. $file = $CFG->dataroot . '/temp/' . $key;
  728. if ($key == $application_xml->file_jar)
  729. copy($file, $root_ilm . "/" . $key);
  730. unlink($file);
  731. } // foreach ($files_extract as $key => $value)
  732. return $root_ilm . "/" . $application_xml->file_jar;
  733. }
  734. /// Function for list the directory where iLM is allocated.
  735. // @param type $dir
  736. // @return type
  737. static function list_directory ($dir) {
  738. $files = array();
  739. $cont = 0;
  740. $ffs = scandir($dir);
  741. unset($ffs[array_search('.', $ffs, true)]);
  742. unset($ffs[array_search('..', $ffs, true)]);
  743. if (count($ffs) < 1) {
  744. return;
  745. }
  746. foreach ($ffs as $ff) {
  747. $files[$cont] = $dir . "/" . $ff;
  748. $cont++;
  749. if (is_dir($dir . '/' . $ff)) {
  750. $temp = self::list_directory($dir . '/' . $ff);
  751. foreach ($temp as $t) {
  752. $files[$cont] = $t;
  753. $cont++;
  754. }
  755. }
  756. }
  757. return $files;
  758. }
  759. /// Function for delete directory where the iLM is allocated.
  760. // @param string $dirPath
  761. // @throws InvalidArgumentException
  762. public static function delete_dir ($dirPath) {
  763. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  764. $dirPath .= '/';
  765. }
  766. $files = glob($dirPath . '*', GLOB_MARK);
  767. foreach ($files as $file) {
  768. if (is_dir($file)) {
  769. self::delete_dir($file);
  770. } else {
  771. unlink($file);
  772. }
  773. }
  774. rmdir($dirPath);
  775. }
  776. }
  777. ?>