install.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.3 2020/08/30
  12. * + Removed all commands associated to 'upgrade'
  13. * - v 1.5.2 2020/08/03
  14. * + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL
  15. * + New version of iHanoi 1.0.20200803
  16. * - v 1.5.1 2020/05/28-30
  17. * + Avoid to update one iLM causing colision with other instance of the same iLM
  18. * - v 1.4 2013/09/19
  19. * + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
  20. * + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
  21. * - v 1.2 2013/08/30
  22. * + Change 'filearea' for new concept for files.
  23. * + Change path file for ilm, consider version in pathname.
  24. *
  25. * @author Leônidas O. Brandão
  26. * @author Patricia Alves Rodrigues
  27. * @author Igor Moreira Félix
  28. * @version v 1.5.3 2020/08/30
  29. * @version v 1.5.1 2020/05/28-30
  30. * @version v 1.5 2019/03/13
  31. * @version v 1.4 2013/09/19
  32. * @package mod_iassign_db
  33. * @since 2010/12/21
  34. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  35. *
  36. * <b>License</b>
  37. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38. *
  39. * @param $oldversion Number of the old version.
  40. */
  41. require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
  42. ///
  43. // Code run after the mod_iassign module database tables have been created.
  44. // Disables this plugin for new installs
  45. // @return bool
  46. function xmldb_iassign_install () {
  47. // function xmldb_iassign_upgrade ($oldversion)
  48. global $CFG, $DB, $USER;
  49. $dbman = $DB->get_manager();
  50. // iLM availables: iFractions; iGeom; iGraf; iHanoi; iVProg; Risko
  51. // HTML+JS iLM : iFractions; iHanoi; iVProg
  52. // Java iLM : iGeom; iGraf
  53. $table = new xmldb_table('iassign_submission');
  54. $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
  55. if (!$dbman->field_exists($table, $field)) {
  56. $dbman->add_field($table, $field);
  57. }
  58. $records = array(
  59. array_combine( // iVProg 1.0.20200121 - HTML5
  60. array('name', 'url', 'version', 'type', 'description',
  61. 'extension', 'file_jar', 'file_class', 'width', 'height',
  62. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
  63. array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20200121', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}',
  64. 'ivph', 'ilm/iVProg/1.0.20190717/ivprog/', 'index.html', 800, 600,
  65. 1, 1, 1, time(), $USER->id, time())),
  66. array_combine( // iHanoi 1.0.20200803 - HTML5
  67. array('name', 'url', 'version', 'type', 'description',
  68. 'extension', 'file_jar', 'file_class', 'width', 'height',
  69. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
  70. array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}',
  71. 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500,
  72. 1, 1, 1, time(), $USER->id, time())),
  73. array_combine( // iFractions 0.1.20200221 - HTML5
  74. array('name', 'url', 'version', 'type', 'description',
  75. 'extension', 'file_jar', 'file_class', 'width', 'height',
  76. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
  77. array('iFractions', 'http://www.matematica.br/ifractions', '0.1.20200221', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}',
  78. 'frc', 'ilm/iFractions/0.1.20200221/ifractions/', 'index.html', 1000, 600,
  79. 1, 1, 0, time(), $USER->id, time())),
  80. array_combine( // iGeom 5.9.22 - Java
  81. array('name', 'url', 'version', 'type', 'description',
  82. 'extension', 'file_jar', 'file_class', 'width', 'height',
  83. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
  84. array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}',
  85. 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600,
  86. 1, 1, 0, time(), $USER->id, time())),
  87. array_combine( // Risco 2.2.23 - Java
  88. array('name', 'url', 'version', 'type', 'description',
  89. 'extension', 'file_jar', 'file_class', 'width', 'height',
  90. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated'),
  91. 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"}',
  92. 'rsk', 'ilm/Risko/2.2.23/Risko.jar', 'RiskoApplet.class', 800, 600,
  93. 1, 0, 0, time(), $USER->id, time()))
  94. );
  95. $strInstalled_iLM = "";
  96. $error = 0;
  97. foreach ($records as $record) {
  98. $newentry = new stdClass();
  99. $newentry->name = $record['name'];
  100. $newentry->version = $record['version'];
  101. $newentry->type = $record['type'];
  102. $newentry->url = $record['url'];
  103. $newentry->description = $record['description'];
  104. $newentry->extension = $record['extension'];
  105. $newentry->file_jar = $record['file_jar'];
  106. $newentry->file_class = $record['file_class'];
  107. $newentry->width = $record['width'];
  108. $newentry->height = $record['height'];
  109. $newentry->enable = $record['enable'];
  110. $newentry->evaluate = $record['evaluate'];
  111. $newentry->reevaluate = $record['reevaluate'];
  112. $newentry->timemodified = time();
  113. $newentry->author = $USER->id;
  114. $newentry->timecreated = time();
  115. try {
  116. $DB->insert_record("iassign_ilm", $newentry, false);
  117. $strInstalled_iLM .= "\n" . ' <li>' . $record['name'] . ';' . $record['type'] . ';' . $record['version'] . ' </li>' . "\n";
  118. } catch (Exception $e) {
  119. print "Error install.php: " . $e->getMessage() . "<br/>";
  120. $error = 1;
  121. }
  122. }
  123. if ($error == 1) {
  124. // $string['error_security_no_userid'] = 'Internal error: must be informed the user identification. Inform the Administrator.';
  125. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  126. print get_string('error_security_no_userid', 'iassign'); // Internal error: must be informed the user identification. Inform the Administrator
  127. // print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' + "\n";
  128. print '</div>' + "\n";
  129. }
  130. else { // $string['cliinstallfinished'] = 'Installation completed successfully.';
  131. print '<div class="modal-content"><p>' . get_string('cliinstallfinished', 'install') . '</p>' . "\n";
  132. print ' <ul style="margin-top: 1rem;">' . "\n";
  133. print $strInstalled_iLM;
  134. print ' </ul>' . "\n";
  135. print '</div' . "\n";;
  136. }
  137. // log event -----------------------------------------------------
  138. if (class_exists('plugin_manager'))
  139. $pluginman = plugin_manager::instance();
  140. else
  141. $pluginman = core_plugin_manager::instance();
  142. $plugins = $pluginman->get_plugins();
  143. iassign_log::add_log('install', 'version: ' . $plugins['mod']['iassign']->versiondisk);
  144. // log event -----------------------------------------------------
  145. return true;
  146. } // function xmldb_iassign_install()