install.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * This file keeps track of brand new installation of iAssign.
  4. *
  5. * iAssign allow insertion of new "interactive Learning Modules" (iLM),
  6. * at any times, by the Moodle administrator.
  7. * It cames with some iLM from Laboratory of Informatics in Education (LInE),
  8. * like iVProg (www.matematica.br/ivprog) and iFractions (www.matematica.br/ifractions).
  9. * The purpose of this scritp is to insert theses initial iLM in your iAssign module.
  10. *
  11. * - v 1.5.5 2023/05/04
  12. * + Added new version of iVProg 2023_05_04 with Portugol/English direct encoding
  13. * - v 1.5.4 2021/12/23
  14. * + Added new version of iVProg 2021_11_30_22_06
  15. * - v 1.5.3 2020/08/30
  16. * + Removed all commands associated to 'upgrade'
  17. * - v 1.5.2 2020/08/03
  18. * + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL
  19. * + New version of iHanoi 1.0.20200803
  20. * - v 1.5.1 2020/05/28-30
  21. * + Avoid to update one iLM causing colision with other instance of the same iLM
  22. * - v 1.4 2013/09/19
  23. * + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
  24. * + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
  25. * - v 1.2 2013/08/30
  26. * + Change 'filearea' for new concept for files.
  27. * + Change path file for ilm, consider version in pathname.
  28. *
  29. * @author Leo^nidas de Oliveira Brandao
  30. * @author Patricia Alves Rodrigues
  31. * @author Igor Moreira Fe'lix
  32. * @version v 1.5.5 2023/05/04: iVProg 2023_05_04
  33. * @version v 1.5.4 2021/12/23: iVProg 2021_11_30_22_06
  34. * @version v 1.5.3 2020/08/30
  35. * @version v 1.5.1 2020/05/28-30
  36. * @version v 1.5 2019/03/13
  37. * @version v 1.4 2013/09/19
  38. * @package mod_iassign_db
  39. * @since 2010/12/21
  40. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  41. *
  42. * <b>License</b>
  43. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44. *
  45. * @param $oldversion Number of the old version.
  46. */
  47. require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
  48. ///
  49. // Code run after the mod_iassign module database tables have been created.
  50. // Disables this plugin for new installs
  51. // @return bool
  52. function xmldb_iassign_install () {
  53. // function xmldb_iassign_upgrade ($oldversion)
  54. global $CFG, $DB, $USER;
  55. $dbman = $DB->get_manager();
  56. // iLM availables: iFractions; iGeom; iGraf; iHanoi; iVProg; Risko
  57. // HTML+JS iLM : iFractions; iHanoi; iVProg
  58. // Java iLM : iGeom; iGraf
  59. $table = new xmldb_table('iassign_submission');
  60. $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
  61. if (!$dbman->field_exists($table, $field)) {
  62. $dbman->add_field($table, $field);
  63. }
  64. $records = array(
  65. array_combine( // iVProg 1.0.20230504 - HTML5
  66. array('name', 'url', 'version', 'type', 'description',
  67. 'extension', 'file_jar', 'file_class', 'width', 'height',
  68. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  69. 'editingbehavior', 'submissionbehavior', 'action_buttons'),
  70. array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20230504', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}',
  71. 'ivph', 'ilm/iVProg/1.0.20230504/ivprog/', 'index.html', 900, 700,
  72. 1, 1, 1, time(), $USER->id, time(),
  73. 1, 0, 1)),
  74. array_combine( // iHanoi 1.0.20230526 - HTML5
  75. array('name', 'url', 'version', 'type', 'description',
  76. 'extension', 'file_jar', 'file_class', 'width', 'height',
  77. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  78. 'editingbehavior', 'submissionbehavior', 'action_buttons'),
  79. array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20230526', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}',
  80. 'ihn', 'ilm/iHanoi/1.0.20230526/ihanoi/', 'index.html', 1100, 500,
  81. 1, 1, 1, time(), $USER->id, time(),
  82. 0, 0, 1)),
  83. array_combine( // iFractions 3.1.0 - HTML5
  84. array('name', 'url', 'version', 'type', 'description',
  85. 'extension', 'file_jar', 'file_class', 'width', 'height',
  86. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  87. 'editingbehavior', 'submissionbehavior', 'action_buttons'),
  88. array('iFractions', 'http://www.matematica.br/ifractions', '3.1.0', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}',
  89. 'frc', 'ilm/iFractions/3.1.0/ifractions/', 'index.html', 1000, 600,
  90. 1, 1, 0, time(), $USER->id, time(),
  91. 0, 1, 0)),
  92. array_combine( // iGeom 5.9.22 - Java
  93. array('name', 'url', 'version', 'type', 'description',
  94. 'extension', 'file_jar', 'file_class', 'width', 'height',
  95. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  96. 'editingbehavior', 'submissionbehavior', 'action_buttons'),
  97. array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}',
  98. 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600,
  99. 1, 1, 0, time(), $USER->id, time(),
  100. 0, 0, 1)),
  101. array_combine( // Risco 2.2.23 - Java
  102. array('name', 'url', 'version', 'type', 'description',
  103. 'extension', 'file_jar', 'file_class', 'width', 'height',
  104. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  105. 'editingbehavior', 'submissionbehavior', 'action_buttons'),
  106. array('Risko', 'http://risko.pcc.usp.br/', '2.2.23', 'Java', '{"en":"Technical drawing with triangle and ruler","pt_br":"Desenho Geomẽtrico com esquadro"}',
  107. 'rsk', 'ilm/Risko/2.2.23/Risko.jar', 'RiskoApplet.class', 800, 600,
  108. 1, 0, 0, time(), $USER->id, time(),
  109. 1, 0, 1))
  110. );
  111. $strInstalled_iLM = "";
  112. $error = 0;
  113. foreach ($records as $record) {
  114. $newentry = new stdClass();
  115. $newentry->name = $record['name'];
  116. $newentry->version = $record['version'];
  117. $newentry->type = $record['type'];
  118. $newentry->url = $record['url'];
  119. $newentry->description = $record['description'];
  120. $newentry->extension = $record['extension'];
  121. $newentry->file_jar = $record['file_jar'];
  122. $newentry->file_class = $record['file_class'];
  123. $newentry->width = $record['width'];
  124. $newentry->height = $record['height'];
  125. $newentry->enable = $record['enable'];
  126. $newentry->evaluate = $record['evaluate'];
  127. $newentry->reevaluate = $record['reevaluate'];
  128. $newentry->timemodified = time();
  129. $newentry->author = $USER->id;
  130. $newentry->timecreated = time();
  131. $newentry->editingbehavior = $record['editingbehavior'];
  132. $newentry->submissionbehavior = $record['submissionbehavior'];
  133. $newentry->action_buttons = $record['action_buttons'];
  134. try {
  135. $DB->insert_record("iassign_ilm", $newentry, false);
  136. $strInstalled_iLM .= "\n" . ' <li>' . $record['name'] . ';' . $record['type'] . ';' . $record['version'] . ' </li>' . "\n";
  137. } catch (Exception $e) {
  138. print "Error install.php: " . $e->getMessage() . "<br/>";
  139. $error = 1;
  140. }
  141. }
  142. if ($error == 1) {
  143. // $string['error_security_no_userid'] = 'Internal error: must be informed the user identification. Inform the Administrator.';
  144. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  145. print get_string('error_security_no_userid', 'iassign'); // Internal error: must be informed the user identification. Inform the Administrator
  146. // print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' + "\n";
  147. print '</div>' + "\n";
  148. }
  149. else { // $string['cliinstallfinished'] = 'Installation completed successfully.';
  150. print '<div class="modal-content"><p>' . get_string('cliinstallfinished', 'install') . '</p>' . "\n";
  151. print ' <ul style="margin-top: 1rem;">' . "\n";
  152. print $strInstalled_iLM;
  153. print ' </ul>' . "\n";
  154. print '</div' . "\n";;
  155. }
  156. // Create $CFG->dataroot/temp/iassign_files
  157. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  158. if (!file_exists($tempfilespath)) {
  159. mkdir($tempfilespath, 0777, true);
  160. }
  161. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  162. if (!file_exists($iassignfilespath)) {
  163. mkdir($iassignfilespath, 0777, true);
  164. }
  165. // log event -----------------------------------------------------
  166. if (class_exists('plugin_manager'))
  167. $pluginman = plugin_manager::instance();
  168. else
  169. $pluginman = core_plugin_manager::instance();
  170. $plugins = $pluginman->get_plugins();
  171. iassign_log::add_log('install', 'version: ' . $plugins['mod']['iassign']->versiondisk);
  172. // log event -----------------------------------------------------
  173. return true;
  174. } // function xmldb_iassign_install()