settings_ilm.php 10 KB

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