settings_ilm.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. // Get all fields of this iLM: name, type, set_lang, description_lang, author, action, timecreated, timemodified, parent, ...
  56. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class ilm_settings: add_edit_copy_ilm($ilm_id, $action)
  57. //D echo "settings_ilm.php: edit: $title"; // echo "param->description="; print_r($param->description);
  58. //D $description = $param->description_lang; // used to present the iLM description in 'settings_form.php'
  59. //D $description = $param->description; //TODO in 'settings_form.php' it does NOT present the description!!!
  60. $description = $param->description_lang; // used to present the iLM description in 'settings_form.php' - {"en":"...","pt":"..."}
  61. $mform = new mod_ilm_form(); // in 'settings_form.php': class mod_ilm_form
  62. //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
  63. //DEBUg: since bellow fills form data
  64. $mform->set_data($param);
  65. if ($mform->is_cancelled()) {
  66. close_window();
  67. die;
  68. }
  69. else if ($formdata = $mform->get_submitted_data()) { // chegando aqui com $formdata->type vazio!
  70. // $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]
  71. ilm_settings::edit_ilm($formdata, $formdata->file); // localib.php: class ilm_settings
  72. close_window(0, true);
  73. die;
  74. }
  75. print $OUTPUT->header();
  76. print $OUTPUT->heading($title); // put the header title
  77. $mform->display();
  78. print $OUTPUT->footer();
  79. die;
  80. } // if ($action == 'edit')
  81. else
  82. if ($action == 'new_version') { // Administration > plugins > iAssign : after select the iLM and the option 'Add new iLM version'
  83. $title = get_string('new_version_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  84. $PAGE->set_title($title);
  85. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action); // locallib.php: class iassign
  86. $mform = new mod_ilm_form();
  87. $mform->set_data($param);
  88. if ($mform->is_cancelled()) {
  89. close_window();
  90. die;
  91. }
  92. else { // Final form processing! Registered by 'locallib.php' with ilm_settings::copy_new_version_ilm($formdata)
  93. $formdata = $mform->get_data();
  94. if ($formdata) { // already exists the iLM
  95. //D echo "settings_ilm.php: FINAL!<br/>"; print_r($formdata);
  96. ilm_settings::copy_new_version_ilm($formdata); // locallib.php: class ilm_settings
  97. close_window(0, true);
  98. die;
  99. }
  100. }
  101. print($OUTPUT->header());
  102. print($OUTPUT->heading($title));
  103. $mform->display();
  104. print($OUTPUT->footer());
  105. die;
  106. }
  107. else
  108. if ($action == 'copy') {
  109. $title = get_string('copy_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  110. $PAGE->set_title($title);
  111. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  112. $mform = new mod_ilm_form();
  113. $mform->set_data($param);
  114. if ($mform->is_cancelled()) {
  115. close_window();
  116. die;
  117. }
  118. else if ($formdata = $mform->get_data()) {
  119. ilm_settings::copy_new_version_ilm($formdata);
  120. close_window(0, true);
  121. die;
  122. }
  123. print($OUTPUT->header());
  124. print($OUTPUT->heading($title));
  125. $mform->display();
  126. print($OUTPUT->footer());
  127. die;
  128. }
  129. else
  130. if ($action == 'add') {
  131. $title = get_string('add_ilm_iassign', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  132. $PAGE->set_title($title);
  133. $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  134. $mform = new mod_ilm_form();
  135. $mform->set_data($param);
  136. if ($mform->is_cancelled()) {
  137. close_window();
  138. die;
  139. }
  140. else if ($formdata = $mform->get_data()) {
  141. $extension = explode(".", $mform->get_new_filename('file'));
  142. if ($extension[count($extension) - 1] == 'ipz') {
  143. $retorno = ilm_settings::new_ilm($formdata->file);
  144. if($retorno == true) {
  145. close_window(0, true);
  146. die;
  147. }
  148. } else
  149. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  150. }
  151. print($OUTPUT->header());
  152. print($OUTPUT->heading($title));
  153. $mform->display();
  154. print($OUTPUT->footer());
  155. die;
  156. }
  157. else
  158. if ($action == 'import') {
  159. $title = get_string('import_ilm', 'iassign') . $OUTPUT->help_icon('import_ilm', 'iassign');
  160. $PAGE->set_title($title);
  161. $param = new stdClass();
  162. $param->action = $action;
  163. $CFG->action_ilm = $action;
  164. $mform = new mod_ilm_form();
  165. $mform->set_data($param);
  166. if ($mform->is_cancelled()) {
  167. close_window();
  168. die;
  169. }
  170. else if ($formdata = $mform->get_data()) {
  171. $extension = explode(".", $mform->get_new_filename('file'));
  172. if ($extension[count($extension) - 1] == 'ipz') {
  173. $retorno = ilm_settings::import_ilm($formdata->file);
  174. if ($retorno == true) {
  175. close_window(5, true);
  176. die;
  177. }
  178. }
  179. else
  180. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  181. }
  182. print($OUTPUT->header());
  183. print($OUTPUT->heading($title));
  184. $mform->display();
  185. print($OUTPUT->footer());
  186. die;
  187. }
  188. else
  189. if ($action == 'confirm_delete_ilm') {
  190. $title = get_string('delete_ilm', 'iassign');
  191. $PAGE->set_title($title);
  192. $PAGE->set_pagelayout('base');
  193. $delete_ilm = ilm_settings::confirm_delete_ilm($ilm_id, $ilm_parent);
  194. print($OUTPUT->header());
  195. print($OUTPUT->heading($title));
  196. print($delete_ilm);
  197. print($OUTPUT->footer());
  198. die;
  199. }
  200. else
  201. if ($action == 'delete') {
  202. $title = get_string('delete_ilm', 'iassign');
  203. $PAGE->set_title($title);
  204. $PAGE->set_pagelayout('redirect');
  205. $parent = ilm_settings::delete_ilm($ilm_id);
  206. if ($parent == null) {
  207. $title = get_string('delete_ilm', 'iassign');
  208. $PAGE->set_title($title);
  209. $PAGE->set_pagelayout('base');
  210. $delete_ilm = ilm_settings::confirm_delete_ilm($ilm_id, $ilm_parent);
  211. print($OUTPUT->header());
  212. print($OUTPUT->heading($title));
  213. print($OUTPUT->notification(get_string('error_folder_permission_denied', 'iassign'), 'notifyproblem'));
  214. print($delete_ilm);
  215. print($OUTPUT->footer());
  216. die;
  217. }
  218. if ($parent == 0)
  219. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'view')));
  220. else
  221. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent)));
  222. }
  223. else
  224. if ($action == 'confirm_default_ilm') {
  225. $title = get_string('confirm_default', 'iassign');
  226. $PAGE->set_title($title);
  227. $PAGE->set_pagelayout('base');
  228. $default_ilm = ilm_settings::confirm_default_ilm($ilm_id, $ilm_parent);
  229. print($OUTPUT->header());
  230. print($default_ilm);
  231. print($OUTPUT->footer());
  232. die;
  233. }
  234. else
  235. if ($action == 'default') {
  236. $title = get_string('default_ilm', 'iassign');
  237. $PAGE->set_title($title);
  238. $PAGE->set_pagelayout('redirect');
  239. ilm_settings::default_ilm($ilm_id);
  240. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent)));
  241. }
  242. else
  243. if ($action == 'list') {
  244. $title = get_string('list_ilm', 'iassign');
  245. $PAGE->set_title($title);
  246. $list_ilm = ilm_settings::list_ilm();
  247. print($OUTPUT->header());
  248. print($OUTPUT->heading($title . $OUTPUT->help_icon('list_ilm', 'iassign')));
  249. print($list_ilm);
  250. print($OUTPUT->footer());
  251. die;
  252. }
  253. else
  254. if ($action == 'upgrade') {
  255. $title = get_string('upgrade_ilm_title', 'iassign');
  256. $PAGE->set_title($title);
  257. $PAGE->set_pagelayout('redirect');
  258. $ilm = ilm_settings::upgrade_ilm($ilm_id);
  259. if ($ilm == 0)
  260. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'view')));
  261. else
  262. redirect(new moodle_url('/admin/settings.php?', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm)));
  263. }
  264. else
  265. if ($action == 'view') {
  266. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  267. $title = get_string('view_ilm', 'iassign') . $OUTPUT->help_icon('add_ilm_iassign', 'iassign');
  268. $PAGE->set_title($title . ': ' . $iassign_ilm->name . ' ' . $iassign_ilm->version);
  269. $view_ilm = ilm_settings::view_ilm($ilm_id, $from);
  270. print($OUTPUT->header());
  271. print($OUTPUT->heading($title . ': ' . $iassign_ilm->name . ' ' . $iassign_ilm->version));
  272. print($view_ilm);
  273. print($OUTPUT->footer());
  274. die;
  275. }