install.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. 'editingbehavior', 'submissionbehavior'),
  64. 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"}',
  65. 'ivph', 'ilm/iVProg/1.0.20190717/ivprog/', 'index.html', 800, 600,
  66. 1, 1, 1, time(), $USER->id, time(),
  67. 1, 0)),
  68. array_combine( // iHanoi 1.0.20200803 - HTML5
  69. array('name', 'url', 'version', 'type', 'description',
  70. 'extension', 'file_jar', 'file_class', 'width', 'height',
  71. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  72. 'editingbehavior', 'submissionbehavior'),
  73. 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)"}',
  74. 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500,
  75. 1, 1, 1, time(), $USER->id, time(),
  76. 0, 0)),
  77. array_combine( // iFractions 0.1.20200221 - HTML5
  78. array('name', 'url', 'version', 'type', 'description',
  79. 'extension', 'file_jar', 'file_class', 'width', 'height',
  80. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  81. 'editingbehavior', 'submissionbehavior'),
  82. array('iFractions', 'http://www.matematica.br/ifractions', '0.1.20200221', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}',
  83. 'frc', 'ilm/iFractions/0.1.20200221/ifractions/', 'index.html', 1000, 600,
  84. 1, 1, 0, time(), $USER->id, time(),
  85. 0, 1)),
  86. array_combine( // iGeom 5.9.22 - Java
  87. array('name', 'url', 'version', 'type', 'description',
  88. 'extension', 'file_jar', 'file_class', 'width', 'height',
  89. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  90. 'editingbehavior', 'submissionbehavior'),
  91. array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}',
  92. 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600,
  93. 1, 1, 0, time(), $USER->id, time(),
  94. 0, 0)),
  95. array_combine( // Risco 2.2.23 - Java
  96. array('name', 'url', 'version', 'type', 'description',
  97. 'extension', 'file_jar', 'file_class', 'width', 'height',
  98. 'enable', 'evaluate', 'reevaluate', 'timemodified', 'author', 'timecreated',
  99. 'editingbehavior', 'submissionbehavior'),
  100. 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"}',
  101. 'rsk', 'ilm/Risko/2.2.23/Risko.jar', 'RiskoApplet.class', 800, 600,
  102. 1, 0, 0, time(), $USER->id, time(),
  103. 1, 0))
  104. );
  105. $strInstalled_iLM = "";
  106. $error = 0;
  107. foreach ($records as $record) {
  108. $newentry = new stdClass();
  109. $newentry->name = $record['name'];
  110. $newentry->version = $record['version'];
  111. $newentry->type = $record['type'];
  112. $newentry->url = $record['url'];
  113. $newentry->description = $record['description'];
  114. $newentry->extension = $record['extension'];
  115. $newentry->file_jar = $record['file_jar'];
  116. $newentry->file_class = $record['file_class'];
  117. $newentry->width = $record['width'];
  118. $newentry->height = $record['height'];
  119. $newentry->enable = $record['enable'];
  120. $newentry->evaluate = $record['evaluate'];
  121. $newentry->reevaluate = $record['reevaluate'];
  122. $newentry->timemodified = time();
  123. $newentry->author = $USER->id;
  124. $newentry->timecreated = time();
  125. $newentry->editingbehavior = $record['editingbehavior'];
  126. $newentry->submissionbehavior = $record['submissionbehavior'];
  127. try {
  128. $DB->insert_record("iassign_ilm", $newentry, false);
  129. $strInstalled_iLM .= "\n" . ' <li>' . $record['name'] . ';' . $record['type'] . ';' . $record['version'] . ' </li>' . "\n";
  130. } catch (Exception $e) {
  131. print "Error install.php: " . $e->getMessage() . "<br/>";
  132. $error = 1;
  133. }
  134. }
  135. if ($error == 1) {
  136. // $string['error_security_no_userid'] = 'Internal error: must be informed the user identification. Inform the Administrator.';
  137. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  138. print get_string('error_security_no_userid', 'iassign'); // Internal error: must be informed the user identification. Inform the Administrator
  139. // print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' + "\n";
  140. print '</div>' + "\n";
  141. }
  142. else { // $string['cliinstallfinished'] = 'Installation completed successfully.';
  143. print '<div class="modal-content"><p>' . get_string('cliinstallfinished', 'install') . '</p>' . "\n";
  144. print ' <ul style="margin-top: 1rem;">' . "\n";
  145. print $strInstalled_iLM;
  146. print ' </ul>' . "\n";
  147. print '</div' . "\n";;
  148. }
  149. // log event -----------------------------------------------------
  150. if (class_exists('plugin_manager'))
  151. $pluginman = plugin_manager::instance();
  152. else
  153. $pluginman = core_plugin_manager::instance();
  154. $plugins = $pluginman->get_plugins();
  155. iassign_log::add_log('install', 'version: ' . $plugins['mod']['iassign']->versiondisk);
  156. // log event -----------------------------------------------------
  157. return true;
  158. } // function xmldb_iassign_install()