MDL-23232 added support for enrol_plugin->all_enrol() which indicates plugin allows...
[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
35$config = optional_param('config', 0, PARAM_INT);
36$hide = optional_param('hide', 0, PARAM_INT);
67a87e7d 37$course = optional_param('course', SITEID, PARAM_INT);
38
a6855934 39$url = new moodle_url('/user/portfolio.php', array('course'=>$course));
ce221eb5 40if ($hide !== 0) {
41 $url->param('hide', $hide);
42}
43if ($config !== 0) {
44 $url->param('config', $config);
45}
46$PAGE->set_url($url);
47
67a87e7d 48if (! $course = $DB->get_record("course", array("id"=>$course))) {
49 print_error('invalidcourseid');
50}
51
52$user = $USER;
53$fullname = fullname($user);
54$strportfolios = get_string('portfolios', 'portfolio');
55$configstr = get_string('manageyourportfolios', 'portfolio');
56$namestr = get_string('name');
57$pluginstr = get_string('plugin', 'portfolio');
58$baseurl = $CFG->wwwroot . '/user/portfolio.php';
59
60$display = true; // set this to false in the conditions to stop processing
61
62require_login($course, false);
63
caa8363f 64echo $OUTPUT->header();
55de6e07 65$currenttab = 'portfolioconf';
67a87e7d 66$showroles = 1;
67include('tabs.php');
68
69if (!empty($config)) {
70 $instance = portfolio_instance($config);
71 $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
72 if ($mform->is_cancelled()){
73 redirect($baseurl);
74 exit;
75 } else if ($fromform = $mform->get_data()){
76 if (!confirm_sesskey()) {
77 print_error('confirmsesskeybad', '', $baseurl);
78 }
79 //this branch is where you process validated data.
80 $success = $instance->set_user_config($fromform, $USER->id);
81 //$success = $success && $instance->save();
82 if ($success) {
83 redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
84 } else {
85 print_error('instancenotsaved', 'portfolio', $baseurl);
86 }
87 exit;
88 } else {
8fa89bfd 89 echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
3aac07d8 90 echo $OUTPUT->box_start();
67a87e7d 91 $mform->display();
3aac07d8 92 echo $OUTPUT->box_end();
67a87e7d 93 $display = false;
94 }
95
96} else if (!empty($hide)) {
97 $instance = portfolio_instance($hide);
98 $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
99}
100
101if ($display) {
8fa89bfd 102 echo $OUTPUT->heading($configstr);
3aac07d8 103 echo $OUTPUT->box_start();
67a87e7d 104
105 if (!$instances = portfolio_instances(true, false)) {
106 print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
107 }
108
f2f085ee 109 $table = new html_table();
67a87e7d 110 $table->head = array($namestr, $pluginstr, '');
111 $table->data = array();
112
113 foreach ($instances as $i) {
114 $visible = $i->get_user_config('visible', $USER->id);
115 $table->data[] = array($i->get('name'), $i->get('plugin'),
d6d24b88 116 ($i->has_user_config()
b5d0cafc
PS
117 ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" alt="' . get_string('configure') . '" /></a>' : '') .
118 ' <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 119 );
120 }
121
16be8974 122 echo html_writer::table($table);
cc2e5b13 123 echo $OUTPUT->box_end();
67a87e7d 124}
0ab75c34 125echo $OUTPUT->footer();
67a87e7d 126