settings_ilm.php 8.6 KB

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