MDL-15860 - add global portfolio enabled switch
[moodle.git] / user / portfolio.php
CommitLineData
67a87e7d 1<?php
2
3require_once(dirname(dirname(__FILE__)) . '/config.php');
a239f01e 4
5if (empty($CFG->portfolioenabled)) {
6 print_error('disabled', 'portfolio');
7}
8
67a87e7d 9require_once($CFG->libdir . '/portfoliolib.php');
10
11$config = optional_param('config', 0, PARAM_INT);
12$hide = optional_param('hide', 0, PARAM_INT);
13
14$course = optional_param('course', SITEID, PARAM_INT);
15
16if (! $course = $DB->get_record("course", array("id"=>$course))) {
17 print_error('invalidcourseid');
18}
19
20$user = $USER;
21$fullname = fullname($user);
22$strportfolios = get_string('portfolios', 'portfolio');
23$configstr = get_string('manageyourportfolios', 'portfolio');
24$namestr = get_string('name');
25$pluginstr = get_string('plugin', 'portfolio');
26$baseurl = $CFG->wwwroot . '/user/portfolio.php';
27
28$display = true; // set this to false in the conditions to stop processing
29
30require_login($course, false);
31
32$navlinks[] = array('name' => $fullname, 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id, 'type' => 'misc');
33$navlinks[] = array('name' => $strportfolios, 'link' => null, 'type' => 'misc');
34
35$navigation = build_navigation($navlinks);
36
37print_header("$course->fullname: $fullname: $strportfolios", $course->fullname,
38 $navigation, "", "", true, "&nbsp;", navmenu($course));
39
40$currenttab = 'portfolios';
41$showroles = 1;
42include('tabs.php');
43
44if (!empty($config)) {
45 $instance = portfolio_instance($config);
46 $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
47 if ($mform->is_cancelled()){
48 redirect($baseurl);
49 exit;
50 } else if ($fromform = $mform->get_data()){
51 if (!confirm_sesskey()) {
52 print_error('confirmsesskeybad', '', $baseurl);
53 }
54 //this branch is where you process validated data.
55 $success = $instance->set_user_config($fromform, $USER->id);
56 //$success = $success && $instance->save();
57 if ($success) {
58 redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
59 } else {
60 print_error('instancenotsaved', 'portfolio', $baseurl);
61 }
62 exit;
63 } else {
64 print_heading(get_string('configplugin', 'portfolio'));
65 print_simple_box_start();
66 $mform->display();
67 print_simple_box_end();
68 $display = false;
69 }
70
71} else if (!empty($hide)) {
72 $instance = portfolio_instance($hide);
73 $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
74}
75
76if ($display) {
77 print_heading($configstr);
78 print_simple_box_start();
79
80 if (!$instances = portfolio_instances(true, false)) {
81 print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
82 }
83
84 $table = new StdClass;
85 $table->head = array($namestr, $pluginstr, '');
86 $table->data = array();
87
88 foreach ($instances as $i) {
89 $visible = $i->get_user_config('visible', $USER->id);
90 $table->data[] = array($i->get('name'), $i->get('plugin'),
d6d24b88 91 ($i->has_user_config()
67a87e7d 92 ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $CFG->pixpath . '/t/edit.gif" alt="' . get_string('configure') . '" /></a>' : '') .
93 ' <a href="' . $baseurl . '?hide=' . $i->get('id') . '"><img src="' . $CFG->pixpath . '/t/' . (($visible) ? 'hide' : 'show') . '.gif" alt="' . get_string($visible ? 'hide' : 'show') . '" /></a><br />'
94 );
95 }
96
97 print_table($table);
98}
99print_footer();
100
101?>