1
0

install.php 9.0 KB

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