PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/feature/copy/copy.php

https://github.com/NigelCunningham/moodle-mod_forumng
PHP | 71 lines | 35 code | 10 blank | 26 comment | 5 complexity | ae81e7cc5a02411c1685a24f96a1fbda MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Copy script. Copies forum reference into session, after confirm form.
  18. * @package forumngfeature
  19. * @subpackage copy
  20. * @copyright 2011 The Open University
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once('../../../../config.php');
  24. require_once($CFG->dirroot . '/mod/forumng/mod_forumng.php');
  25. $d = required_param('d', PARAM_INT);
  26. $pageparams = array('d' => $d);
  27. $cloneid = optional_param('clone', 0, PARAM_INT);
  28. if ($cloneid) {
  29. $pageparams['clone'] = $cloneid;
  30. }
  31. $discussion = mod_forumng_discussion::get_from_id($d, $cloneid);
  32. $forum = $discussion->get_forum();
  33. $cm = $forum->get_course_module();
  34. $course = $forum->get_course();
  35. // Require that you can see this discussion (etc) and copy them
  36. $discussion->require_view();
  37. require_capability('mod/forumng:copydiscussion',
  38. $discussion->get_forum()->get_context());
  39. $pagename = get_string('copy_title', 'forumngfeature_copy');
  40. $pageurl = new moodle_url('/mod/forumng/feature/copy/copy.php', $pageparams);
  41. $out = $discussion->init_page($pageurl, $pagename);
  42. // Create form
  43. require_once('forumngfeature_copy_form.php');
  44. $mform = new forumngfeature_copy_form('copy.php', array('d'=>$d, 'clone'=>$cloneid));
  45. if ($mform->is_cancelled()) {
  46. redirect('../../discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_PLAIN));
  47. } else if (($fromform = $mform->get_data(false)) ||
  48. get_user_preferences('forumng_hidecopyhelp', 0)) {
  49. // Remember in session that the discussion is being copied
  50. $SESSION->forumng_copyfrom = $d;
  51. $SESSION->forumng_copyfromclone = $cloneid;
  52. if (!empty($fromform->hidelater)) {
  53. set_user_preference('forumng_hidecopyhelp', 1);
  54. }
  55. // Redirect back to view page
  56. redirect($forum->get_url(mod_forumng::PARAM_PLAIN));
  57. }
  58. print $out->header();
  59. // Print form
  60. $mform->display();
  61. print $out->footer();