1
0

java.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. <?php
  2. /**
  3. * Class that implements ilm_handle, in order to allow manipulation and management of Java iLM
  4. *
  5. * @author Igor Moreira Félix
  6. * @author Patricia Alves Rodrigues
  7. * @author Leônidas O. Brandã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. $content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
  180. if ($special_param1 == 1 && !empty($student_answer) && (!$view_teacherfileversion)) { // is script
  181. $view_teacherfileversion = true; // here when student is doing/redoing his activity
  182. }
  183. elseif (!$view_teacherfileversion) { // Student seem his solution or teacher it (of one student)
  184. $content_or_id_from_ilm_security = $student_answer;
  185. }
  186. }
  187. else {
  188. if ($view_teacherfileversion) { // $view_teacherfileversion==1 => load the exercise ('activity') from the 'moodledata' (id in 'files')
  189. // $content_or_id_from_ilm_security = $this->context->id;
  190. $content_or_id_from_ilm_security = $fileid; // $iassign_statement_activity_item->file;
  191. } else { // $view_teacherfileversion==null => load the learner answer from the data base (iassign_submission)
  192. $content_or_id_from_ilm_security = $student_answer;
  193. }
  194. }
  195. $allow_submission = false; // There is permission to 'submission' button?
  196. if ($USER->iassignEdit == 1 && $student_answer) { // for now, only iVProg2 and iVProgH5 allows editions of exercise already sent
  197. $allow_submission = true; // yes!
  198. $write_solution = 1;
  199. $enderecoPOST .= "&write_solution=1"; // complement POST address indicating that the learner could send edited solution
  200. }
  201. // Security: this avoid the student get a second access to the file content (usually an exercise)
  202. // Data are registered in the table '*_iassign_security' bellow and is erased by function 'view()' above.
  203. // IMPORTANT: the '$end_file' will receive the iLM content URL using the security filter './mod/iassign/ilm_security.php'
  204. // the iLM must request the content using this URL. Data are registered in the table '*_iassign_security'.
  205. // Attention : using iVProgH5 there are lot of " and the use of slashes (as '\"') will imply in iVProgH5 do not read the file!
  206. // do not use: $id_iLM_security = $this->write_iLM_security($iassign_statement_activity_item->id, addslashes($content_or_id_from_ilm_security));
  207. //2017 $id_iLM_security = $this->write_iLM_security($iassign_statement_activity_item->id, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  208. //2017 $this->remove_old_iLM_security_entries($USER->id, $iassign_statement_activity_item->id); // additional security: erase eventually old entries
  209. require_once ($CFG->dirroot . '/mod/iassign/ilm_security.php');
  210. $timecreated = time();
  211. $token = md5($timecreated); // iassign_iLM_security->timecreated);
  212. // Try to get the student answer
  213. // In './ilm_security.php': write_iLM_security($userid, $timecreated, $iassign_statementid = -1, $content_or_id_from_ilm_security)
  214. $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'
  215. // $iassign_iLM_security = $DB->get_record("iassign_security", array("id" => $id_iLM_security));
  216. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $id_iLM_security . '&token=' . $token . '&view=' . $view_teacherfileversion; // need full path...
  217. //TODO iLM_HTML5 :: Need to use '*_iassign_ilm.ilm_type' in { 'jar', 'html5' }
  218. //TODO iLM_HTML5 :: For now I use the particular case of
  219. //leo Ou usar: if ($extension == "html" || $extension == "ivph") // if iLM is HTML5 is inside a frame
  220. $iassign = "
  221. <script type='text/javascript'>
  222. //<![CDATA[
  223. function jsAnalyseAnswer () {
  224. var strAnswer = document.applets[0].getAnswer(); //leo estava comentado!
  225. var evaluationResult = document.applets[0].getEvaluation(); //leo estava comentado!
  226. var comment = document.formEnvio.submission_comment.value;
  227. if ((strAnswer==null || strAnswer=='' || strAnswer==-1) && (comment==null || comment=='')) { // undefined
  228. alert('" . get_string('activity_empty', 'iassign') . "');
  229. return false; // success
  230. }
  231. else {
  232. document.formEnvio.iLM_PARAM_ArchiveContent.value = strAnswer;
  233. document.formEnvio.iLM_PARAM_ActivityEvaluation.value = evaluationResult;
  234. document.formEnvio.submit();
  235. return true; // any error...
  236. }
  237. }
  238. //]]>
  239. </script>\n"; //
  240. $iassign .= "\n<center>\n<form name='formEnvio' id='formEnvio' method='post' action='$enderecoPOST' enctype='multipart/form-data'>\n";
  241. // Attention: The actual iLM content will be provided by the indirect access in './mod/iassign/ilm_security.php',
  242. // bellow only the 'token' to the content will be shown in URL (by security reason). The iLM must use this URL on
  243. // 'MA_PARAM_Proposition' to request the content.
  244. // Calls static function bellow: parameters are data to store in table '*_iassign_submission'
  245. //leo $iassign .= ilm_settings::build_ilm_tags($this->ilm->id, array(
  246. $iassign .= ilm_settings::build_ilm_tags($ilm->id, array(//leo para testar 'iassign_security'
  247. "type" => "activity",
  248. "notSEND" => "false",
  249. "addresPOST" => $enderecoPOST,
  250. "Proposition" => $end_file,
  251. "special_param" => $special_param1,
  252. "student_answer" => $student_answer,
  253. "id_iLM_security" => $id_iLM_security,
  254. "iassign_statement" => $iassign_statement_activity_item->id // MOOC 2016
  255. ));
  256. if (!isguestuser() && $iassign_statement_activity_item->type_iassign != 1
  257. && ($ilm->editingbehavior == 1 || ($ilm->editingbehavior == 0 && !in_array($_GET['action'], array('viewsubmission', 'view'))))) {
  258. $iassign .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>\n";
  259. $iassign .= " <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>\n";
  260. if (!has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  261. $iassign .= " <p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  262. else
  263. $iassign .= " <input type='hidden' name='submission_comment'>\n";
  264. if ($allow_submission) { // it is not iGeom
  265. $iassign .= "<center>\n<!-- load button -->\n" .
  266. " <input type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
  267. get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
  268. } else {
  269. // Works with 'javascript:window.jsAnalyseAnswer()' or simply 'jsAnalyseAnswer()'
  270. $iassign .= "<center>\n<!-- load button -->\n" .
  271. " <input type=button value='" . get_string('submit_iassign', 'iassign') . "' onClick = 'javascript:window.jsAnalyseAnswer();' title='" .
  272. get_string('message_submit_iassign', 'iassign') . "'>\n" . "</center>\n";
  273. }
  274. } // if (!isguestuser() && $iassign_statement_activity_item->type_iassign != 1)
  275. elseif ($ilm->editingbehavior == 0) {
  276. $iassign .= "<center><br><a href=\"view.php?action=repeat&id=".$_GET['id']
  277. ."&iassign_current=".$_GET['iassign_current']."\">
  278. <input type='button' value='".get_string('repeat', 'iassign')."'></a></center>";
  279. }
  280. $iassign .= "</form></center>\n\n";
  281. return $iassign;
  282. }
  283. /**
  284. * Exibe os dados de um iLM
  285. */
  286. public static function view_ilm($ilmid, $from) {
  287. global $DB;
  288. $url = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
  289. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  290. $str = "";
  291. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  292. $str .= '<tr>';
  293. $str .= '<td colspan=3 align=right>';
  294. if ($from != 'admin') {
  295. $str .= '<input type=button value="' . get_string('return', 'iassign') . '" onclick="javascript:window.location = \'' . $_SERVER['HTTP_REFERER'] . '\';">' . "\n";
  296. }
  297. $str .= '<input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close();">';
  298. $str .= '</td>' . "\n";
  299. $str .= '</tr>' . "\n";
  300. if ($iassign_ilm) {
  301. $iassign_statement_activity_item = $DB->get_records('iassign_statement', array("iassign_ilmid" => $iassign_ilm->id));
  302. if ($iassign_statement_activity_item) {
  303. $total = count($iassign_statement_activity_item);
  304. } else {
  305. $total = 0;
  306. }
  307. if ($from == 'admin') {
  308. $str .= '<tr><td colspan=2>' . "\n";
  309. $str .= '<table width="100%" class="generaltable boxaligncenter" >' . "\n";
  310. $str .= '<tr>' . "\n";
  311. $str .= '<td class=\'cell c0 actvity\' ><strong>' . get_string('activities', 'iassign') . ':</strong>&nbsp;' . $total . '</td>' . "\n";
  312. $str .= '<td><strong>' . get_string('url_ilm', 'iassign') . '</strong>&nbsp;<a href="' . $iassign_ilm->url . '">' . $iassign_ilm->url . '</a></td>' . "\n";
  313. $str .= '</tr>' . "\n";
  314. $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";
  315. $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";
  316. $str .= '<td width="50%"><strong>' . get_string('width', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->width;
  317. $str .= '&nbsp;&nbsp;<strong>' . get_string('height', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->height . '</td></tr>' . "\n";
  318. $str .= '<tr><td><strong>' . get_string('file_jar', 'iassign') . ':</strong>&nbsp;' . basename($iassign_ilm->file_jar) . '</td>' . "\n";
  319. $str .= '<td ><strong>' . get_string('file_class', 'iassign') . ':</strong>&nbsp;' . $iassign_ilm->file_class . '</td></tr>' . "\n";
  320. if ($iassign_ilm->evaluate == 1) {
  321. $evaluate = get_string('yes', 'iassign');
  322. } else {
  323. $evaluate = get_string('no', 'iassign');
  324. }
  325. $str .= '<tr><td width="50%"><strong>' . get_string('evaluate', 'iassign') . ':</strong>&nbsp;' . $evaluate . '</td>' . "\n";
  326. if ($iassign_ilm->enable == 1) {
  327. $enable = get_string('yes', 'iassign');
  328. } else {
  329. $enable = get_string('no', 'iassign');
  330. }
  331. $str .= '<td width="50%"><strong>' . get_string('enable', 'iassign') . ':</strong>&nbsp;' . $enable . '</td></tr>' . "\n";
  332. $str .= '<tr>' . "\n";
  333. $str .= '<td width="50%"><strong>' . get_string('file_created', 'iassign') . ':</strong>&nbsp;' . userdate($iassign_ilm->timecreated) . '</td>' . "\n";
  334. $str .= '<td width="50%"><strong>' . get_string('file_modified', 'iassign') . ':</strong>&nbsp;' . userdate($iassign_ilm->timemodified) . '</td>' . "\n";
  335. $str .= '</tr>' . "\n";
  336. $user_ilm = $DB->get_record('user', array('id' => $iassign_ilm->author));
  337. if ($user_ilm) {
  338. $str .= '<tr>' . "\n";
  339. $str .= '<td colspan=2><strong>' . get_string('author', 'iassign') . ':</strong>&nbsp;' . $user_ilm->firstname . '&nbsp;' . $user_ilm->lastname . '</td>' . "\n";
  340. $str .= '</tr>' . "\n";
  341. }
  342. $str .= '</table>' . "\n";
  343. $str .= '</td></tr>' . "\n";
  344. }
  345. if (!empty($iassign_ilm->file_jar)) {
  346. //TODO: REVIEW: to be used for parameters of "applet" from DB
  347. $options = array("type" => "view"); //MOOC2014: start
  348. $str .= '<tr class=\'cell c0 actvity\'><td colspan=3 align=center bgcolor="#F5F5F5">' . "\n";
  349. // Second parameter null since 'iassign_security' are not define yet
  350. $str .= ilm_settings::build_ilm_tags($iassign_ilm->id, $options);
  351. //TODO: REVIEW: missing code to manage parameters
  352. //MOOC2014: tem este codigo!
  353. } else {
  354. $str .= '<tr class=\'cell c0 actvity\'>' . "\n";
  355. $str .= '<td colspan=2 align=center>' . get_string('null_file', 'iassign') . '</td>' . "\n";
  356. $str .= '<td align=center><a href="' . $url . '</a></td>' . "\n";
  357. $str .= '</tr>' . "\n";
  358. }
  359. $str .= '</td></tr>' . "\n";
  360. }
  361. $str .= '</table>' . "\n";
  362. return $str;
  363. }
  364. /**
  365. * Copia ou gera uma nova versão do iLM
  366. */
  367. public static function copy_new_version_ilm($param, $files_extract) {
  368. global $DB, $CFG;
  369. $iassign_ilm = new stdClass();
  370. $iassign_ilm->name = $param->name;
  371. $iassign_ilm->version = $param->version;
  372. $iassign_ilm->file_jar = null;
  373. $file_jar = null;
  374. if (!is_null($files_extract)) {
  375. foreach ($files_extract as $key => $value) {
  376. if (strpos(strtolower($key), ".jar")) {
  377. $extract = new stdClass();
  378. $extract->file_jar = $key;
  379. $extract->name = $param->name;
  380. $extract->version = $param->version;
  381. echo $key;
  382. $file_jar = self::save_ilm_by_xml($extract, $files_extract)[0];
  383. echo $file_jar;
  384. break;
  385. }
  386. }
  387. }
  388. $description = json_decode($param->description_lang);
  389. $description->{$param->set_lang} = $param->description;
  390. $newentry = new stdClass();
  391. $newentry->name = $param->name;
  392. $newentry->version = $param->version;
  393. $newentry->type = "Java";
  394. $newentry->url = $param->url;
  395. $newentry->description = strip_tags(json_encode($description));
  396. $newentry->extension = strtolower($param->extension);
  397. if (!is_null($file_jar)) {
  398. $newentry->file_jar = $file_jar;
  399. }
  400. $newentry->file_class = $param->file_class;
  401. $newentry->width = $param->width;
  402. $newentry->height = $param->height;
  403. $newentry->enable = 0;
  404. $newentry->timemodified = $param->timemodified;
  405. $newentry->timecreated = $param->timecreated;
  406. $newentry->evaluate = $param->evaluate;
  407. $newentry->author = $param->author;
  408. $newentry->parent = $param->parent;
  409. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  410. // log event --------------------------------------------------------------------------------------
  411. iassign_log::add_log('copy_iassign_ilm', 'name: ' . $param->name . ' ' . $param->version, 0, $newentry->id);
  412. // log event --------------------------------------------------------------------------------------
  413. }
  414. /// Export an iLM to a package of the iLM (with its descriptor XML)
  415. public static function export_ilm ($ilm_id) {
  416. global $DB, $CFG;
  417. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  418. $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $ilm_id)); //MOOC 2016
  419. $files_jar = str_replace(basename($iassign_ilm->file_jar), "", $iassign_ilm->file_jar);
  420. $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '_' . date("Ymd-Hi") . '.ipz';
  421. $zip = new zip_archive();
  422. $zip->open($zip_filename);
  423. $rootdir = $CFG->dirroot . '/mod/iassign/' . $files_jar;
  424. $allfiles = self::list_directory($rootdir);
  425. $i = 0;
  426. $base_jar = "";
  427. foreach ($allfiles as $file) {
  428. $mini = basename(str_replace($CFG->dirroot . '/mod/iassign/ilm/', "", $file));
  429. if (!is_dir($file)) {
  430. $zip->add_file_from_pathname($mini, $file);
  431. $base_jar = $mini;
  432. }
  433. }
  434. $application_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  435. $application_descriptor .= '<application xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  436. $application_descriptor .= ' <name>' . $iassign_ilm->name . '</name>' . "\n";
  437. $application_descriptor .= ' <url>' . $iassign_ilm->url . '</url>' . "\n";
  438. $application_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  439. $application_descriptor .= ' <type>' . $iassign_ilm->type . '</type>' . "\n";
  440. $application_descriptor .= ' <description>' . html_entity_decode(str_replace(array('<p>', '</p>'), array('', ''), $iassign_ilm->description)) . '</description>' . "\n";
  441. $application_descriptor .= ' <extension>' . $iassign_ilm->extension . '</extension>' . "\n";
  442. $application_descriptor .= ' <file_jar>' . $base_jar . '</file_jar>' . "\n";
  443. $application_descriptor .= ' <file_class>' . $iassign_ilm->file_class . '</file_class>' . "\n";
  444. $application_descriptor .= ' <width>' . $iassign_ilm->width . '</width>' . "\n";
  445. $application_descriptor .= ' <height>' . $iassign_ilm->height . '</height>' . "\n";
  446. $application_descriptor .= ' <evaluate>' . $iassign_ilm->evaluate . '</evaluate>' . "\n";
  447. if ($iassign_ilm_configs) { //MOOC 2016
  448. $application_descriptor .= ' <params>' . "\n";
  449. foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  450. $application_descriptor .= ' <param>' . "\n";
  451. $application_descriptor .= ' <type>' . $iassign_ilm_config->param_type . '</type>' . "\n";
  452. $application_descriptor .= ' <name>' . $iassign_ilm_config->param_name . '</name>' . "\n";
  453. $application_descriptor .= ' <value>' . $iassign_ilm_config->param_value . '</value>' . "\n";
  454. $application_descriptor .= ' <description>' . htmlentities(str_replace("\n", "", $iassign_ilm_config->description)) . '</description>' . "\n";
  455. $application_descriptor .= ' <visible>' . $iassign_ilm_config->visible . '</visible>' . "\n";
  456. $application_descriptor .= ' </param>' . "\n";
  457. }
  458. $application_descriptor .= ' </params>' . "\n";
  459. } //MOOC 2016
  460. $application_descriptor .= '</application>' . "\n";
  461. $zip->add_file_from_string('ilm-application.xml', $application_descriptor);
  462. $zip->close();
  463. header("Pragma: public");
  464. header("Expires: 0");
  465. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  466. header("Cache-Control: private", false);
  467. header("Content-Type: application/zip");
  468. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  469. header("Content-Transfer-Encoding: binary");
  470. header("Content-Length: " . @filesize($zip_filename));
  471. set_time_limit(0);
  472. @readfile("$zip_filename") || die("File not found.");
  473. unlink($zip_filename);
  474. exit;
  475. }
  476. public static function delete_ilm($ilm_id) {
  477. global $DB, $CFG, $OUTPUT;
  478. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  479. // Prepare the path of directory to be removed
  480. $path_w = rtrim($iassign_ilm->file_jar, "/");
  481. $folder_to_remove = substr($path_w, 0, strrpos($path_w, '/') + 1);
  482. // Check if the iLM directory is writable
  483. if (!is_writable($iassign_ilm->file_jar)) {
  484. return null;
  485. }
  486. self::delete_dir($folder_to_remove);
  487. $ilm_folder = "ilm/" . $iassign_ilm->name . "/";
  488. $k = 0;
  489. // Verify if iLM parent directory is empty, if yes, remove it
  490. foreach(glob($ilm_folder . "*", GLOB_ONLYDIR) as $dir) {
  491. $k ++;
  492. break;
  493. }
  494. if ($k == 0) {
  495. self::delete_dir($ilm_folder);
  496. }
  497. $DB->delete_records("iassign_ilm", array('id' => $ilm_id));
  498. $DB->delete_records("iassign_ilm_config", array('iassign_ilmid' => $ilm_id)); //MOOC 2016
  499. // log event --------------------------------------------------------------------------------------
  500. iassign_log::add_log('delete_iassign_ilm', 'name: ' . $iassign_ilm->name . ' ' . $iassign_ilm->version, 0, $iassign_ilm->id);
  501. // log event --------------------------------------------------------------------------------------
  502. return $iassign_ilm->parent;
  503. }
  504. /*public static function delete_ilm($ilm_id) {
  505. global $DB, $CFG;
  506. $fs = get_file_storage();
  507. $contextsystem = context_system::instance();
  508. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  509. $files_jar = explode(",", $iassign_ilm->file_jar);
  510. foreach ($files_jar as $file_jar) {
  511. $file = $fs->get_file_by_id($file_jar);
  512. if ($file)
  513. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  514. }
  515. $DB->delete_records("iassign_ilm", array('id' => $ilm_id));
  516. $DB->delete_records("iassign_ilm_config", array('iassign_ilmid' => $ilm_id)); //MOOC 2016
  517. // log event --------------------------------------------------------------------------------------
  518. iassign_log::add_log('delete_iassign_ilm', 'name: ' . $iassign_ilm->name . ' ' . $iassign_ilm->version, 0, $iassign_ilm->id);
  519. // log event --------------------------------------------------------------------------------------
  520. return $iassign_ilm->parent;
  521. }*/
  522. /// Register data from an iLM after to updated it
  523. public static function edit_ilm ($param, $itemid, $files_extract, $contextuser) {
  524. global $DB, $CFG;
  525. $iassign_ilm = new stdClass();
  526. $iassign_ilm->name = $param->name;
  527. $iassign_ilm->version = $param->version;
  528. $iassign_ilm->file_jar = $param->file_jar;
  529. $file_jar = null;
  530. if (!is_null($files_extract)) {
  531. foreach ($files_extract as $key => $value) {
  532. if (strpos(strtolower($key), ".jar")) {
  533. $extract = new stdClass();
  534. $extract->file_jar = $key;
  535. $extract->name = $param->name;
  536. $extract->version = $param->version;
  537. echo $key;
  538. $file_jar = self::save_ilm_by_xml($extract, $files_extract)[0];
  539. echo $file_jar;
  540. break;
  541. }
  542. }
  543. }
  544. $description = json_decode($param->description_lang);
  545. $description->{$param->set_lang} = $param->description;
  546. $updentry = new stdClass();
  547. $updentry->id = $param->id;
  548. $updentry->version = $param->version;
  549. $updentry->url = $param->url;
  550. $updentry->description = strip_tags(json_encode($description));
  551. $updentry->extension = strtolower($param->extension);
  552. if (!is_null($file_jar)) {
  553. $updentry->file_jar = $file_jar;
  554. }
  555. $updentry->file_class = $param->file_class;
  556. $updentry->width = $param->width;
  557. $updentry->height = $param->height;
  558. $updentry->enable = $param->enable;
  559. $updentry->timemodified = $param->timemodified;
  560. $updentry->evaluate = $param->evaluate;
  561. $DB->update_record("iassign_ilm", $updentry);
  562. // log event --------------------------------------------------------------------------------------
  563. iassign_log::add_log('update_iassign_ilm', 'name: ' . $param->name . ' ' . $param->version, 0, $param->id);
  564. // log event --------------------------------------------------------------------------------------
  565. }
  566. /**
  567. * Realiza os procedimentos relacionados ao armazenamento dos dados do iLM e seus arquivos
  568. */
  569. public static function new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs) {
  570. global $DB, $CFG, $USER, $OUTPUT;
  571. $description_str = str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML());
  572. $iassign_ilm = $DB->get_record('iassign_ilm', array("name" => (String) $application_xml->name, "version" => (String) $application_xml->version));
  573. if ($iassign_ilm) {
  574. foreach ($files_extract as $key => $value) {
  575. $file = $CFG->dataroot . '/temp/' . $key;
  576. if (file_exists($file))
  577. unlink($file);
  578. }
  579. print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
  580. } else {
  581. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  582. if (empty($file_jar))
  583. print_error('error_add_ilm', 'iassign');
  584. else { // if (empty($file_jar))
  585. $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
  586. if (!$iassign_ilm) {
  587. $iassign_ilm = new stdClass(); //MOOC 2016
  588. $iassign_ilm->id = 0;
  589. }
  590. $newentry = new stdClass();
  591. $newentry->name = (String) $application_xml->name;
  592. $newentry->version = (String) $application_xml->version;
  593. $newentry->type = (String) $application_xml->type;
  594. $newentry->url = (String) $application_xml->url;
  595. $newentry->description = strip_tags($description_str);
  596. $newentry->extension = strtolower((String) $application_xml->extension);
  597. $newentry->file_jar = $file_jar;
  598. $newentry->file_class = (String) $application_xml->file_class;
  599. $newentry->width = (String) $application_xml->width;
  600. $newentry->height = (String) $application_xml->height;
  601. $newentry->enable = 0;
  602. $newentry->timemodified = time();
  603. $newentry->author = $USER->id;
  604. $newentry->timecreated = time();
  605. $newentry->evaluate = (String) $application_xml->evaluate;
  606. $newentry->parent = $iassign_ilm->id;
  607. //MOOC 2016 $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  608. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  609. // log event --------------------------------------------------------------------------------------
  610. iassign_log::add_log('add_iassign_ilm', 'name: ' . $application_xml->name . ' ' . $application_xml->version, 0, $newentry->id);
  611. // log event --------------------------------------------------------------------------------------
  612. if ($application_xml->params->param) {
  613. foreach ($application_xml->params->param as $value) {
  614. $newentry = new stdClass();
  615. $newentry->iassign_ilmid = $iassign_ilmid;
  616. $newentry->param_type = (String) $value->type;
  617. $newentry->param_name = (String) $value->name;
  618. $newentry->param_value = (String) $value->value;
  619. $newentry->description = html_entity_decode((String) $value->description);
  620. $newentry->visible = (String) $value->visible;
  621. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  622. if (!$newentry->id) {
  623. print_error('error_add_param', 'iassign');
  624. }
  625. }
  626. }
  627. }
  628. }
  629. $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  630. return true;
  631. }
  632. /**
  633. * Realiza os procedimentos relacionados ao armazenamento de um iLM por meio da importação
  634. */
  635. public static function import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs) {
  636. global $DB, $CFG, $USER, $OUTPUT;
  637. $description_str = str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML());
  638. $iassign_ilm = $DB->get_record('iassign_ilm', array("name" => (String) $application_xml->name, "version" => (String) $application_xml->version));
  639. if ($iassign_ilm) {
  640. foreach ($files_extract as $key => $value) {
  641. $file = $CFG->dataroot . '/temp/' . $key;
  642. if (file_exists($file))
  643. unlink($file);
  644. }
  645. print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
  646. } else {
  647. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  648. if (empty($file_jar))
  649. print_error('error_add_ilm', 'iassign');
  650. else { // if (empty($file_jar))
  651. $iassign_ilm = $DB->get_record('iassign_ilm', array("parent" => 0, "name" => (String) $application_xml->name));
  652. if (!$iassign_ilm) {
  653. $iassign_ilm = new stdClass(); //MOOC 2016
  654. $iassign_ilm->id = 0;
  655. }
  656. $newentry = new stdClass();
  657. $newentry->name = (String) $application_xml->name;
  658. $newentry->version = (String) $application_xml->version;
  659. $newentry->type = (String) $application_xml->type;
  660. $newentry->url = (String) $application_xml->url;
  661. $newentry->description = strip_tags($description_str);
  662. $newentry->extension = strtolower((String) $application_xml->extension);
  663. $newentry->file_jar = implode(",", $file_jar);
  664. $newentry->file_class = (String) $application_xml->file_class;
  665. $newentry->width = (String) $application_xml->width;
  666. $newentry->height = (String) $application_xml->height;
  667. $newentry->enable = 0;
  668. $newentry->timemodified = time();
  669. $newentry->author = $USER->id;
  670. $newentry->timecreated = time();
  671. $newentry->evaluate = (String) $application_xml->evaluate;
  672. $newentry->parent = $iassign_ilm->id;
  673. //MOOC 2016 $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  674. $iassign_ilmid = $DB->insert_record("iassign_ilm", $newentry);
  675. if ($application_xml->params->param) {
  676. foreach ($application_xml->params->param as $value) {
  677. $newentry = new stdClass();
  678. $newentry->iassign_ilmid = $iassign_ilmid;
  679. $newentry->param_type = (String) $value->type;
  680. $newentry->param_name = (String) $value->name;
  681. $newentry->param_value = (String) $value->value;
  682. $newentry->description = html_entity_decode((String) $value->description);
  683. $newentry->visible = (String) $value->visible;
  684. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  685. if (!$newentry->id) {
  686. print_error('error_add_param', 'iassign');
  687. }
  688. }
  689. }
  690. }
  691. print($OUTPUT->notification(get_string('ok_import_ilm_version', 'iassign'), 'notifysuccess'));
  692. } // else if ($iassign_ilm)
  693. $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  694. }
  695. /// Function for save iLM from XML descriptor
  696. // @param array $application_xml Data of XML descriptor
  697. // @param array $files_extract Filenames of extract files
  698. // @return array Return an array content id of JAR files
  699. static function save_ilm_by_xml($application_xml, $files_extract) {
  700. global $CFG, $USER, $OUTPUT;
  701. // Check if the iLM directory is writable
  702. if (!is_writable("ilm/")) {
  703. print($OUTPUT->notification(get_string('error_folder_permission_denied', 'iassign'), 'notifyproblem'));
  704. return null;
  705. }
  706. // Check if iLM directory already exists
  707. if (!file_exists("ilm/" . $application_xml->name)) {
  708. // mkdir("ilm/" . $application_xml->name, 0777, true);
  709. mkdir("ilm/" . $application_xml->name, 0755, true); // permissions: drwxr-xr-x
  710. }
  711. // Check if iLM version already exists in directory
  712. if (!file_exists("ilm/" . $application_xml->name . "/" . $application_xml->version)) {
  713. // mkdir("ilm/" . $application_xml->name . "/" . $application_xml->version, 0777, true);
  714. mkdir("ilm/" . $application_xml->name . "/" . $application_xml->version, 0755, true); // drwxr-xr-x
  715. }
  716. else {
  717. print($OUTPUT->notification(get_string('error_import_ilm_version', 'iassign'), 'notifyproblem'));
  718. return null;
  719. }
  720. $root_ilm = "ilm/" . $application_xml->name . "/" . $application_xml->version;
  721. // Extract iLM files to directory
  722. foreach ($files_extract as $key => $value) {
  723. $file = $CFG->dataroot . '/temp/' . $key;
  724. if ($key == $application_xml->file_jar)
  725. copy($file, $root_ilm . "/" . $key);
  726. unlink($file);
  727. } // foreach ($files_extract as $key => $value)
  728. return $root_ilm . "/" . $application_xml->file_jar;
  729. }
  730. /// Function for list the directory where iLM is allocated.
  731. // @param type $dir
  732. // @return type
  733. static function list_directory ($dir) {
  734. $files = array();
  735. $cont = 0;
  736. $ffs = scandir($dir);
  737. unset($ffs[array_search('.', $ffs, true)]);
  738. unset($ffs[array_search('..', $ffs, true)]);
  739. if (count($ffs) < 1) {
  740. return;
  741. }
  742. foreach ($ffs as $ff) {
  743. $files[$cont] = $dir . "/" . $ff;
  744. $cont++;
  745. if (is_dir($dir . '/' . $ff)) {
  746. $temp = self::list_directory($dir . '/' . $ff);
  747. foreach ($temp as $t) {
  748. $files[$cont] = $t;
  749. $cont++;
  750. }
  751. }
  752. }
  753. return $files;
  754. }
  755. /// Function for delete directory where the iLM is allocated.
  756. // @param string $dirPath
  757. // @throws InvalidArgumentException
  758. public static function delete_dir ($dirPath) {
  759. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  760. $dirPath .= '/';
  761. }
  762. $files = glob($dirPath . '*', GLOB_MARK);
  763. foreach ($files as $file) {
  764. if (is_dir($file)) {
  765. self::delete_dir($file);
  766. } else {
  767. unlink($file);
  768. }
  769. }
  770. rmdir($dirPath);
  771. }
  772. }
  773. ?>