settings_ilm.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. /**
  3. * Settings iLM manager. Reaches this code from administrative Moodle area, in setting 'plugins' of iAssign.
  4. * 1. action==new_version: allow enter a new version of a selected iLM
  5. * 2. action==new_version
  6. *
  7. * Release Notes:
  8. * - v 2.0.1 2022/09/15
  9. * + Considering table 'iassign_ilm': messages to fields 'evaluate', 'reevaluate', 'editingbehavior'; fixes to allow the edition of 'reevaluate', 'editingbehavior'
  10. * - v 1.6.1 2017/12/02
  11. * + Changed 'echo' to 'print'
  12. * - v 1.6 2013/10/31
  13. * + Insert support of import iLM from zip packages.
  14. * - v 1.5 2013/10/24
  15. * + Insert function for upgrade an iLM.
  16. * - v 1.4 2013/08/02
  17. * + Insert list of iLMs informations for teacher view.
  18. * - v 1.3 2013/07/12
  19. * + Insert actions: copy (new version from an iLM) and new version (empty new version).
  20. *
  21. * @author Patricia Alves Rodrigues
  22. * @author Leo^nidas de Oliveira Branda~o
  23. * @version v 2.0.1 2022/09/15
  24. * @package mod_iassign_settings
  25. * @since 2013/01/29
  26. * @see locallib.php : class ilm_settings
  27. * @see settings_form.php
  28. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  29. *
  30. * <b>License</b>
  31. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. global $CFG, $USER, $PAGE, $OUTPUT, $DB;
  34. require_once("../../config.php");
  35. require_once($CFG->dirroot . '/mod/iassign/locallib.php');
  36. require_once($CFG->dirroot . '/mod/iassign/settings_form.php');
  37. require_login();
  38. if (isguestuser()) {
  39. die();
  40. }
  41. //Parameters GET e POST (parâmetros GET e POST)
  42. $ilm_id = optional_param('ilm_id', 0, PARAM_INT);
  43. $ilmid = optional_param('ilmid', 0, PARAM_INT);
  44. $ilm_parent = optional_param('ilm_parent', 0, PARAM_INT);
  45. $status = optional_param('status', 0, PARAM_INT);
  46. $action = optional_param('action', NULL, PARAM_TEXT);
  47. $url = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
  48. $from = optional_param('from', NULL, PARAM_TEXT);
  49. $contextuser = context_user::instance($USER->id);
  50. $PAGE->set_url($url);
  51. $PAGE->set_context($contextuser);
  52. $PAGE->blocks->show_only_fake_blocks(); //
  53. $PAGE->set_pagelayout('popup');
  54. if ($action == 'edit') { // Edit data of an iLM => processed in 'settings_form.php'
  55. $title = get_string('edit_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  56. $PAGE->set_title($title);
  57. // Get all fields of this iLM: name, type, set_lang, description_lang, author, action, timecreated, timemodified, parent, ...
  58. // On the first time $ilm_id is well defined, but on the second (it is empty), however we need to call "add_edit_copy_ilm(.)"
  59. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class ilm_settings: add_edit_copy_ilm($ilm_id, $action)
  60. // On the first call $ilm_id is defined: the calling is necessary to fill in data to the form
  61. // on the second call $ilm_id empty and could be avoided
  62. //? if ($ilm_id) $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class ilm_settings: add_edit_copy_ilm($ilm_id, $action)
  63. //? else $param = new stdClass();
  64. // without 'ilm_settings::add_edit_copy_ilm(.)' the process are not successfully finished
  65. //D echo "settings_ilm.php: edit: $title"; // echo "param->description="; print_r($param->description);
  66. //D $description = $param->description_lang; // used to present the iLM description in 'settings_form.php'
  67. //D $description = $param->description; //TODO in 'settings_form.php' it does NOT present the description!!!
  68. $description = $param->description_lang; // used to present the iLM description in 'settings_form.php' - {"en":"...","pt":"..."}
  69. $mform = new mod_ilm_form(); // in 'settings_form.php': class mod_ilm_form
  70. //DEBUG: do NOT use "mod_ilm_form($param)" Warning: htmlspecialchars() expects parameter 1 to be string, object given in /var/www/html/saw/lib/pear/HTML/Common.php on line 177
  71. //DEBUg: since bellow fills form data
  72. $mform->set_data($param);
  73. if ($mform->is_cancelled()) {
  74. close_window();
  75. die;
  76. }
  77. else if ($formdata = $mform->get_submitted_data()) { // chegando aqui com $formdata->type vazio!
  78. // $formdata = { [name] [version] [type]vazio! [url] [lang] [description] [extension] [width] [height] [evaluate] [file] [id] [set_lang] [description_lang] [author] [action] [timecreated] [timemodified] [parent] [enable] [submitbutton]
  79. ilm_settings::edit_ilm($formdata, $formdata->file); // localib.php: class ilm_settings
  80. close_window(0, true);
  81. die;
  82. }
  83. print $OUTPUT->header();
  84. print $OUTPUT->heading($title); // put the header title
  85. $mform->display();
  86. print $OUTPUT->footer();
  87. die;
  88. } // if ($action == 'edit')
  89. else
  90. if ($action == 'new_version') { // Administration > plugins > iAssign : after select the iLM and the option 'Add new iLM version'
  91. $title = get_string('new_version_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  92. $PAGE->set_title($title);
  93. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class iassign
  94. $mform = new mod_ilm_form();
  95. $mform->set_data($param);
  96. if ($mform->is_cancelled()) {
  97. close_window();
  98. die;
  99. }
  100. else { // Final form processing! Registered by 'locallib.php' with ilm_settings::copy_new_version_ilm($formdata)
  101. $formdata = $mform->get_data();
  102. if ($formdata) { // already exists the iLM
  103. //D echo "settings_ilm.php: FINAL!<br/>"; print_r($formdata);
  104. ilm_settings::copy_new_version_ilm($formdata); // locallib.php: class ilm_settings
  105. close_window(0, true);
  106. die;
  107. }
  108. }
  109. print($OUTPUT->header());
  110. print($OUTPUT->heading($title));
  111. $mform->display();
  112. print($OUTPUT->footer());
  113. die;
  114. }
  115. else
  116. if ($action == 'copy') {
  117. $title = get_string('copy_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  118. $PAGE->set_title($title);
  119. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  120. $mform = new mod_ilm_form();
  121. $mform->set_data($param);
  122. if ($mform->is_cancelled()) {
  123. close_window();
  124. die;
  125. }
  126. else if ($formdata = $mform->get_data()) {
  127. ilm_settings::copy_new_version_ilm($formdata);
  128. close_window(0, true);
  129. die;
  130. }
  131. print($OUTPUT->header());
  132. print($OUTPUT->heading($title));
  133. $mform->display();
  134. print($OUTPUT->footer());
  135. die;
  136. }
  137. else
  138. if ($action == 'add') {
  139. $title = get_string('add_ilm_iassign', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  140. $PAGE->set_title($title);
  141. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  142. $mform = new mod_ilm_form();
  143. $mform->set_data($param);
  144. if ($mform->is_cancelled()) {
  145. close_window();
  146. die;
  147. }
  148. else if ($formdata = $mform->get_data()) {
  149. $extension = explode(".", $mform->get_new_filename('file'));
  150. if ($extension[count($extension) - 1] == 'ipz') {
  151. $retorno = ilm_settings::new_ilm($formdata->file);
  152. if($retorno == true) {
  153. close_window(0, true);
  154. die;
  155. }
  156. } else
  157. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  158. }
  159. print($OUTPUT->header());
  160. print($OUTPUT->heading($title));
  161. $mform->display();
  162. print($OUTPUT->footer());
  163. die;
  164. }
  165. else
  166. if ($action == 'import') {
  167. $title = get_string('import_ilm', 'iassign') . $OUTPUT->help_icon('import_ilm', 'iassign');
  168. $PAGE->set_title($title);
  169. $param = new stdClass();
  170. $param->action = $action;
  171. $CFG->action_ilm = $action;
  172. $mform = new mod_ilm_form();
  173. $mform->set_data($param);
  174. if ($mform->is_cancelled()) {
  175. close_window();
  176. die;
  177. }
  178. else if ($formdata = $mform->get_data()) {
  179. $extension = explode(".", $mform->get_new_filename('file'));
  180. if ($extension[count($extension) - 1] == 'ipz') {
  181. $retorno = ilm_settings::import_ilm($formdata->file);
  182. if ($retorno == true) {
  183. close_window(5, true);
  184. die;
  185. }
  186. }
  187. else
  188. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  189. }
  190. print($OUTPUT->header());
  191. print($OUTPUT->heading($title));
  192. $mform->display();
  193. print($OUTPUT->footer());
  194. die;
  195. }
  196. else
  197. if ($action == 'confirm_delete_ilm') {
  198. $title = get_string('delete_ilm', 'iassign');
  199. $PAGE->set_title($title);
  200. $PAGE->set_pagelayout('base');
  201. $delete_ilm = ilm_settings::confirm_delete_ilm($ilm_id, $ilm_parent);
  202. print($OUTPUT->header());
  203. print($OUTPUT->heading($title));
  204. print($delete_ilm);
  205. print($OUTPUT->footer());
  206. die;
  207. }
  208. else
  209. if ($action == 'delete') {
  210. $title = get_string('delete_ilm', 'iassign');
  211. $PAGE->set_title($title);
  212. $PAGE->set_pagelayout('redirect');
  213. $parent = ilm_settings::delete_ilm($ilm_id);
  214. if ($parent == null) {
  215. $title = get_string('delete_ilm', 'iassign');
  216. $PAGE->set_title($title);
  217. $PAGE->set_pagelayout('base');
  218. $delete_ilm = ilm_settings::confirm_delete_ilm($ilm_id, $ilm_parent);
  219. print($OUTPUT->header());
  220. print($OUTPUT->heading($title));
  221. print($OUTPUT->notification(get_string('error_folder_permission_denied', 'iassign'), 'notifyproblem'));
  222. print($delete_ilm);
  223. print($OUTPUT->footer());
  224. die;
  225. }
  226. if ($parent == 0)
  227. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'view')));
  228. else
  229. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent)));
  230. }
  231. else
  232. if ($action == 'confirm_default_ilm') {
  233. $title = get_string('confirm_default', 'iassign');
  234. $PAGE->set_title($title);
  235. $PAGE->set_pagelayout('base');
  236. $default_ilm = ilm_settings::confirm_default_ilm($ilm_id, $ilm_parent);
  237. print($OUTPUT->header());
  238. print($default_ilm);
  239. print($OUTPUT->footer());
  240. die;
  241. }
  242. else
  243. if ($action == 'default') {
  244. $title = get_string('default_ilm', 'iassign');
  245. $PAGE->set_title($title);
  246. $PAGE->set_pagelayout('redirect');
  247. ilm_settings::default_ilm($ilm_id);
  248. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent)));
  249. }
  250. else
  251. if ($action == 'list') {
  252. $title = get_string('list_ilm', 'iassign');
  253. $PAGE->set_title($title);
  254. $list_ilm = ilm_settings::list_ilm();
  255. print($OUTPUT->header());
  256. print($OUTPUT->heading($title . $OUTPUT->help_icon('list_ilm', 'iassign')));
  257. print($list_ilm);
  258. print($OUTPUT->footer());
  259. die;
  260. }
  261. else
  262. if ($action == 'upgrade') {
  263. $title = get_string('upgrade_ilm_title', 'iassign');
  264. $PAGE->set_title($title);
  265. $PAGE->set_pagelayout('redirect');
  266. $ilm = ilm_settings::upgrade_ilm($ilm_id);
  267. if ($ilm == 0)
  268. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'view')));
  269. else
  270. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm)));
  271. }
  272. else
  273. if ($action == 'view') {
  274. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  275. $title = get_string('view_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  276. $PAGE->set_title($title . ': ' . $iassign_ilm->name . ' ' . $iassign_ilm->version);
  277. $view_ilm = ilm_settings::view_ilm($ilm_id, $from);
  278. print($OUTPUT->header());
  279. print($OUTPUT->heading($title . ': ' . $iassign_ilm->name . ' ' . $iassign_ilm->version));
  280. print($view_ilm);
  281. print($OUTPUT->footer());
  282. die;
  283. }