portfolio.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * This file is part of the User section Moodle
  18. *
  19. * @copyright 1999 Martin Dougiamas http://dougiamas.com
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. * @package core_user
  22. */
  23. require_once(__DIR__ . '/../config.php');
  24. if (empty($CFG->enableportfolios)) {
  25. print_error('disabled', 'portfolio');
  26. }
  27. require_once($CFG->libdir . '/portfoliolib.php');
  28. require_once($CFG->libdir . '/portfolio/forms.php');
  29. $config = optional_param('config', 0, PARAM_INT);
  30. $hide = optional_param('hide', 0, PARAM_INT);
  31. $courseid = optional_param('courseid', SITEID, PARAM_INT);
  32. $url = new moodle_url('/user/portfolio.php', array('courseid' => $courseid));
  33. if ($config !== 0) {
  34. $url->param('config', $config);
  35. }
  36. if (! $course = $DB->get_record("course", array("id" => $courseid))) {
  37. print_error('invalidcourseid');
  38. }
  39. $user = $USER;
  40. $fullname = fullname($user);
  41. $strportfolios = get_string('portfolios', 'portfolio');
  42. $configstr = get_string('manageyourportfolios', 'portfolio');
  43. $namestr = get_string('name');
  44. $pluginstr = get_string('plugin', 'portfolio');
  45. $baseurl = $CFG->wwwroot . '/user/portfolio.php';
  46. $introstr = get_string('intro', 'portfolio');
  47. $showhide = get_string('showhide', 'portfolio');
  48. $display = true; // Set this to false in the conditions to stop processing.
  49. require_login($course, false);
  50. $PAGE->set_url($url);
  51. $PAGE->set_context(context_user::instance($user->id));
  52. $PAGE->set_title($configstr);
  53. $PAGE->set_heading($fullname);
  54. $PAGE->set_pagelayout('admin');
  55. echo $OUTPUT->header();
  56. $showroles = 1;
  57. if (!empty($config)) {
  58. navigation_node::override_active_url(new moodle_url('/user/portfolio.php', array('courseid' => $courseid)));
  59. $instance = portfolio_instance($config);
  60. $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
  61. if ($mform->is_cancelled()) {
  62. redirect($baseurl);
  63. exit;
  64. } else if ($fromform = $mform->get_data()) {
  65. if (!confirm_sesskey()) {
  66. print_error('confirmsesskeybad', '', $baseurl);
  67. }
  68. // This branch is where you process validated data.
  69. $instance->set_user_config($fromform, $USER->id);
  70. core_plugin_manager::reset_caches();
  71. redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
  72. exit;
  73. } else {
  74. echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
  75. echo $OUTPUT->box_start();
  76. $mform->display();
  77. echo $OUTPUT->box_end();
  78. $display = false;
  79. }
  80. } else if (!empty($hide)) {
  81. $instance = portfolio_instance($hide);
  82. $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
  83. core_plugin_manager::reset_caches();
  84. }
  85. if ($display) {
  86. echo $OUTPUT->heading($configstr);
  87. echo $OUTPUT->box_start();
  88. echo html_writer::tag('p', $introstr);
  89. if (!$instances = portfolio_instances(true, false)) {
  90. print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
  91. }
  92. $table = new html_table();
  93. $table->head = array($namestr, $pluginstr, $showhide);
  94. $table->data = array();
  95. foreach ($instances as $i) {
  96. $visible = $i->get_user_config('visible', $USER->id);
  97. $table->data[] = array($i->get('name'), $i->get('plugin'),
  98. ($i->has_user_config()
  99. ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" alt="' . get_string('configure') . '" /></a>' : '') .
  100. ' <a href="' . $baseurl . '?hide=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/' . (($visible) ? 'hide' : 'show')) . '" alt="' . get_string($visible ? 'hide' : 'show') . '" /></a><br />'
  101. );
  102. }
  103. echo html_writer::table($table);
  104. echo $OUTPUT->box_end();
  105. }
  106. echo $OUTPUT->footer();