MDL-10110 Adding validation for multichoice option single and multianswer
[moodle.git] / user / portfolio.php
CommitLineData
67a87e7d 1<?php
2
3require_once(dirname(dirname(__FILE__)) . '/config.php');
a239f01e 4
90658eef 5if (empty($CFG->enableportfolios)) {
a239f01e 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
caa8363f 32echo $OUTPUT->header();
55de6e07 33$currenttab = 'portfolioconf';
67a87e7d 34$showroles = 1;
35include('tabs.php');
36
37if (!empty($config)) {
38 $instance = portfolio_instance($config);
39 $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
40 if ($mform->is_cancelled()){
41 redirect($baseurl);
42 exit;
43 } else if ($fromform = $mform->get_data()){
44 if (!confirm_sesskey()) {
45 print_error('confirmsesskeybad', '', $baseurl);
46 }
47 //this branch is where you process validated data.
48 $success = $instance->set_user_config($fromform, $USER->id);
49 //$success = $success && $instance->save();
50 if ($success) {
51 redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
52 } else {
53 print_error('instancenotsaved', 'portfolio', $baseurl);
54 }
55 exit;
56 } else {
8fa89bfd 57 echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
3aac07d8 58 echo $OUTPUT->box_start();
67a87e7d 59 $mform->display();
3aac07d8 60 echo $OUTPUT->box_end();
67a87e7d 61 $display = false;
62 }
63
64} else if (!empty($hide)) {
65 $instance = portfolio_instance($hide);
66 $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
67}
68
69if ($display) {
8fa89bfd 70 echo $OUTPUT->heading($configstr);
3aac07d8 71 echo $OUTPUT->box_start();
67a87e7d 72
73 if (!$instances = portfolio_instances(true, false)) {
74 print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
75 }
76
f2f085ee 77 $table = new html_table();
67a87e7d 78 $table->head = array($namestr, $pluginstr, '');
79 $table->data = array();
80
81 foreach ($instances as $i) {
82 $visible = $i->get_user_config('visible', $USER->id);
83 $table->data[] = array($i->get('name'), $i->get('plugin'),
d6d24b88 84 ($i->has_user_config()
f2a1963c 85 ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/edit') . '" alt="' . get_string('configure') . '" /></a>' : '') .
ddedf979 86 ' <a href="' . $baseurl . '?hide=' . $i->get('id') . '"><img src="' . $OUTPUT->old_icon_url('t/' . (($visible) ? 'hide' : 'show')) . '" alt="' . get_string($visible ? 'hide' : 'show') . '" /></a><br />'
67a87e7d 87 );
88 }
89
f2f085ee 90 echo $OUTPUT->table($table);
67a87e7d 91}
0ab75c34 92echo $OUTPUT->footer();
67a87e7d 93
94?>