NAVIGATION MDL-25468 remove optional_param from navigationlib.php, use override_activ...
[moodle.git] / user / portfolio.php
CommitLineData
67a87e7d 1<?php
2
ce221eb5 3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This file is part of the User section Moodle
20 *
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package user
24 */
25
67a87e7d 26require_once(dirname(dirname(__FILE__)) . '/config.php');
a239f01e 27
90658eef 28if (empty($CFG->enableportfolios)) {
a239f01e 29 print_error('disabled', 'portfolio');
30}
31
67a87e7d 32require_once($CFG->libdir . '/portfoliolib.php');
24ba58ee 33require_once($CFG->libdir . '/portfolio/forms.php');
67a87e7d 34
f6017569
MC
35$config = optional_param('config', 0, PARAM_INT);
36$hide = optional_param('hide', 0, PARAM_INT);
37$courseid = optional_param('courseid', SITEID, PARAM_INT);
67a87e7d 38
f6017569 39$url = new moodle_url('/user/portfolio.php', array('courseid'=>$courseid));
100e0d49 40
ce221eb5 41if ($config !== 0) {
42 $url->param('config', $config);
43}
f6017569 44if (! $course = $DB->get_record("course", array("id"=>$courseid))) {
67a87e7d 45 print_error('invalidcourseid');
46}
47
48$user = $USER;
49$fullname = fullname($user);
50$strportfolios = get_string('portfolios', 'portfolio');
51$configstr = get_string('manageyourportfolios', 'portfolio');
52$namestr = get_string('name');
53$pluginstr = get_string('plugin', 'portfolio');
54$baseurl = $CFG->wwwroot . '/user/portfolio.php';
55
56$display = true; // set this to false in the conditions to stop processing
57
58require_login($course, false);
59
f6017569 60$PAGE->set_url($url);
108ef067 61$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
f6017569
MC
62$PAGE->set_title("$course->fullname: $fullname: $strportfolios");
63$PAGE->set_heading($course->fullname);
64$PAGE->set_pagelayout('standard');
65
caa8363f 66echo $OUTPUT->header();
67a87e7d 67$showroles = 1;
67a87e7d 68
69if (!empty($config)) {
100e0d49 70 navigation_node::override_active_url(new moodle_url('/user/portfolio.php', array('courseid'=>$courseid)));
67a87e7d 71 $instance = portfolio_instance($config);
72 $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
73 if ($mform->is_cancelled()){
74 redirect($baseurl);
75 exit;
76 } else if ($fromform = $mform->get_data()){
77 if (!confirm_sesskey()) {
78 print_error('confirmsesskeybad', '', $baseurl);
79 }
80 //this branch is where you process validated data.
81 $success = $instance->set_user_config($fromform, $USER->id);
82 //$success = $success && $instance->save();
83 if ($success) {
84 redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
85 } else {
86 print_error('instancenotsaved', 'portfolio', $baseurl);
87 }
88 exit;
89 } else {
8fa89bfd 90 echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
3aac07d8 91 echo $OUTPUT->box_start();
67a87e7d 92 $mform->display();
3aac07d8 93 echo $OUTPUT->box_end();
67a87e7d 94 $display = false;
95 }
96
97} else if (!empty($hide)) {
98 $instance = portfolio_instance($hide);
99 $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
100}
101
102if ($display) {
8fa89bfd 103 echo $OUTPUT->heading($configstr);
3aac07d8 104 echo $OUTPUT->box_start();
67a87e7d 105
106 if (!$instances = portfolio_instances(true, false)) {
107 print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
108 }
109
f2f085ee 110 $table = new html_table();
67a87e7d 111 $table->head = array($namestr, $pluginstr, '');
112 $table->data = array();
113
114 foreach ($instances as $i) {
115 $visible = $i->get_user_config('visible', $USER->id);
116 $table->data[] = array($i->get('name'), $i->get('plugin'),
d6d24b88 117 ($i->has_user_config()
b5d0cafc
PS
118 ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" alt="' . get_string('configure') . '" /></a>' : '') .
119 ' <a href="' . $baseurl . '?hide=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/' . (($visible) ? 'hide' : 'show')) . '" alt="' . get_string($visible ? 'hide' : 'show') . '" /></a><br />'
67a87e7d 120 );
121 }
122
16be8974 123 echo html_writer::table($table);
cc2e5b13 124 echo $OUTPUT->box_end();
67a87e7d 125}
0ab75c34 126echo $OUTPUT->footer();
67a87e7d 127