settings_ilm.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * Settings iLM manager.
  4. *
  5. * Release Notes:
  6. * - v 1.6.1 2017/12/02
  7. * + Changed 'echo' to 'print'
  8. * - v 1.6 2013/10/31
  9. * + Insert support of import iLM from zip packages.
  10. * - v 1.5 2013/10/24
  11. * + Insert function for upgrade an iLM.
  12. * - v 1.4 2013/08/02
  13. * + Insert list of iLMs informations for teacher view.
  14. * - v 1.3 2013/07/12
  15. * + Insert actions: copy (new version from an iLM) and new version (empty new version).
  16. *
  17. * @author Patricia Alves Rodrigues
  18. * @author Leônidas O. Brandão
  19. * @version v 1.6.1 2017/12/02
  20. * @package mod_iassign_settings
  21. * @since 2013/01/29
  22. * @see locallib.php : class ilm_settings
  23. * @see settings_form.php
  24. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  25. *
  26. * <b>License</b>
  27. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28. */
  29. global $CFG, $USER, $PAGE, $OUTPUT, $DB;
  30. require_once("../../config.php");
  31. require_once($CFG->dirroot . '/mod/iassign/locallib.php');
  32. require_once($CFG->dirroot . '/mod/iassign/settings_form.php');
  33. require_login();
  34. if (isguestuser()) {
  35. die();
  36. }
  37. //Parameters GET e POST (parâmetros GET e POST)
  38. $ilm_id = optional_param('ilm_id', 0, PARAM_INT);
  39. $ilm_parent = optional_param('ilm_parent', 0, PARAM_INT);
  40. $status = optional_param('status', 0, PARAM_INT);
  41. $action = optional_param('action', NULL, PARAM_TEXT);
  42. $url = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign'));
  43. $from = optional_param('from', NULL, PARAM_TEXT);
  44. $contextuser = context_user::instance($USER->id);
  45. $PAGE->set_url($url);
  46. $PAGE->set_context($contextuser);
  47. $PAGE->blocks->show_only_fake_blocks(); //
  48. $PAGE->set_pagelayout('popup');
  49. if ($action == 'edit') {
  50. $title = get_string('edit_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  51. $PAGE->set_title($title);
  52. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  53. $mform = new mod_ilm_form();
  54. $mform->set_data($param);
  55. if ($mform->is_cancelled()) {
  56. close_window();
  57. die;
  58. }
  59. else if ($formdata = $mform->get_submitted_data()) {
  60. ilm_settings::edit_ilm($formdata, $formdata->file);
  61. close_window(0, true);
  62. die;
  63. }
  64. print($OUTPUT->header());
  65. print($OUTPUT->heading($title));
  66. $mform->display();
  67. print($OUTPUT->footer());
  68. die;
  69. }
  70. else
  71. if ($action == 'new_version') {
  72. $title = get_string('new_version_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  73. $PAGE->set_title($title);
  74. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  75. $mform = new mod_ilm_form();
  76. $mform->set_data($param);
  77. if ($mform->is_cancelled()) {
  78. close_window();
  79. die;
  80. }
  81. else if ($formdata = $mform->get_data()) {
  82. ilm_settings::copy_new_version_ilm($formdata);
  83. close_window(0, true);
  84. die;
  85. }
  86. print($OUTPUT->header());
  87. print($OUTPUT->heading($title));
  88. $mform->display();
  89. print($OUTPUT->footer());
  90. die;
  91. }
  92. else
  93. if ($action == 'copy') {
  94. $title = get_string('copy_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  95. $PAGE->set_title($title);
  96. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  97. $mform = new mod_ilm_form();
  98. $mform->set_data($param);
  99. if ($mform->is_cancelled()) {
  100. close_window();
  101. die;
  102. }
  103. else if ($formdata = $mform->get_data()) {
  104. ilm_settings::copy_new_version_ilm($formdata);
  105. close_window(0, true);
  106. die;
  107. }
  108. print($OUTPUT->header());
  109. print($OUTPUT->heading($title));
  110. $mform->display();
  111. print($OUTPUT->footer());
  112. die;
  113. }
  114. else
  115. if ($action == 'add') {
  116. $title = get_string('add_ilm_iassign', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  117. $PAGE->set_title($title);
  118. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  119. $mform = new mod_ilm_form();
  120. $mform->set_data($param);
  121. if ($mform->is_cancelled()) {
  122. close_window();
  123. die;
  124. } else if ($formdata = $mform->get_data()) {
  125. $extension = explode(".", $mform->get_new_filename('file'));
  126. if ($extension[count($extension) - 1] == 'ipz') {
  127. $retorno = ilm_settings::new_ilm($formdata->file);
  128. if($retorno == true) {
  129. close_window(0, true);
  130. die;
  131. }
  132. } else
  133. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  134. }
  135. print($OUTPUT->header());
  136. print($OUTPUT->heading($title));
  137. $mform->display();
  138. print($OUTPUT->footer());
  139. die;
  140. }
  141. else
  142. if ($action == 'import') {
  143. $title = get_string('import_ilm', 'iassign') . $OUTPUT->help_icon('import_ilm', 'iassign');
  144. $PAGE->set_title($title);
  145. $param = new stdClass();
  146. $param->action = $action;
  147. $CFG->action_ilm = $action;
  148. $mform = new mod_ilm_form();
  149. $mform->set_data($param);
  150. if ($mform->is_cancelled()) {
  151. close_window();
  152. die;
  153. }
  154. else if ($formdata = $mform->get_data()) {
  155. $extension = explode(".", $mform->get_new_filename('file'));
  156. if ($extension[count($extension) - 1] == 'ipz') {
  157. $retorno = ilm_settings::import_ilm($formdata->file);
  158. if ($retorno == true) {
  159. close_window(5, true);
  160. die;
  161. }
  162. }
  163. else
  164. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  165. }
  166. print($OUTPUT->header());
  167. print($OUTPUT->heading($title));
  168. $mform->display();
  169. print($OUTPUT->footer());
  170. die;
  171. }
  172. else
  173. if ($action == 'confirm_delete_ilm') {
  174. $title = get_string('delete_ilm', 'iassign');
  175. $PAGE->set_title($title);
  176. $PAGE->set_pagelayout('base');
  177. $delete_ilm = ilm_settings::confirm_delete_ilm($ilm_id, $ilm_parent);
  178. print($OUTPUT->header());
  179. print($OUTPUT->heading($title));
  180. print($delete_ilm);
  181. print($OUTPUT->footer());
  182. die;
  183. }
  184. else
  185. if ($action == 'delete') {
  186. $title = get_string('delete_ilm', 'iassign');
  187. $PAGE->set_title($title);
  188. $PAGE->set_pagelayout('redirect');
  189. $parent = ilm_settings::delete_ilm($ilm_id);
  190. if ($parent == null) {
  191. $title = get_string('delete_ilm', 'iassign');
  192. $PAGE->set_title($title);
  193. $PAGE->set_pagelayout('base');
  194. $delete_ilm = ilm_settings::confirm_delete_ilm($ilm_id, $ilm_parent);
  195. print($OUTPUT->header());
  196. print($OUTPUT->heading($title));
  197. print($OUTPUT->notification(get_string('error_folder_permission_denied', 'iassign'), 'notifyproblem'));
  198. print($delete_ilm);
  199. print($OUTPUT->footer());
  200. die;
  201. }
  202. if ($parent == 0)
  203. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'view')));
  204. else
  205. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent)));
  206. }
  207. else
  208. if ($action == 'confirm_default_ilm') {
  209. $title = get_string('confirm_default', 'iassign');
  210. $PAGE->set_title($title);
  211. $PAGE->set_pagelayout('base');
  212. $default_ilm = ilm_settings::confirm_default_ilm($ilm_id, $ilm_parent);
  213. print($OUTPUT->header());
  214. print($default_ilm);
  215. print($OUTPUT->footer());
  216. die;
  217. }
  218. else
  219. if ($action == 'default') {
  220. $title = get_string('default_ilm', 'iassign');
  221. $PAGE->set_title($title);
  222. $PAGE->set_pagelayout('redirect');
  223. ilm_settings::default_ilm($ilm_id);
  224. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent)));
  225. }
  226. else
  227. if ($action == 'list') {
  228. $title = get_string('list_ilm', 'iassign');
  229. $PAGE->set_title($title);
  230. $list_ilm = ilm_settings::list_ilm();
  231. print($OUTPUT->header());
  232. print($OUTPUT->heading($title . $OUTPUT->help_icon('list_ilm', 'iassign')));
  233. print($list_ilm);
  234. print($OUTPUT->footer());
  235. die;
  236. }
  237. else
  238. if ($action == 'upgrade') {
  239. $title = get_string('upgrade_ilm_title', 'iassign');
  240. $PAGE->set_title($title);
  241. $PAGE->set_pagelayout('redirect');
  242. $ilm = ilm_settings::upgrade_ilm($ilm_id);
  243. if ($ilm == 0)
  244. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'view')));
  245. else
  246. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm)));
  247. }
  248. else
  249. if ($action == 'view') {
  250. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  251. $title = get_string('view_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  252. $PAGE->set_title($title . ': ' . $iassign_ilm->name . ' ' . $iassign_ilm->version);
  253. $view_ilm = ilm_settings::view_ilm($ilm_id, $from);
  254. print($OUTPUT->header());
  255. print($OUTPUT->heading($title . ': ' . $iassign_ilm->name . ' ' . $iassign_ilm->version));
  256. print($view_ilm);
  257. print($OUTPUT->footer());
  258. die;
  259. }