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