|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 require_once(dirname(dirname(__FILE__)) . '/config.php'); 00027 00028 if (empty($CFG->enableportfolios)) { 00029 print_error('disabled', 'portfolio'); 00030 } 00031 00032 require_once($CFG->libdir . '/portfoliolib.php'); 00033 require_once($CFG->libdir . '/portfolio/forms.php'); 00034 00035 $config = optional_param('config', 0, PARAM_INT); 00036 $hide = optional_param('hide', 0, PARAM_INT); 00037 $courseid = optional_param('courseid', SITEID, PARAM_INT); 00038 00039 $url = new moodle_url('/user/portfolio.php', array('courseid'=>$courseid)); 00040 00041 if ($config !== 0) { 00042 $url->param('config', $config); 00043 } 00044 if (! $course = $DB->get_record("course", array("id"=>$courseid))) { 00045 print_error('invalidcourseid'); 00046 } 00047 00048 $user = $USER; 00049 $fullname = fullname($user); 00050 $strportfolios = get_string('portfolios', 'portfolio'); 00051 $configstr = get_string('manageyourportfolios', 'portfolio'); 00052 $namestr = get_string('name'); 00053 $pluginstr = get_string('plugin', 'portfolio'); 00054 $baseurl = $CFG->wwwroot . '/user/portfolio.php'; 00055 00056 $display = true; // set this to false in the conditions to stop processing 00057 00058 require_login($course, false); 00059 00060 $PAGE->set_url($url); 00061 $PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id)); 00062 $PAGE->set_title("$course->fullname: $fullname: $strportfolios"); 00063 $PAGE->set_heading($course->fullname); 00064 $PAGE->set_pagelayout('standard'); 00065 00066 echo $OUTPUT->header(); 00067 $showroles = 1; 00068 00069 if (!empty($config)) { 00070 navigation_node::override_active_url(new moodle_url('/user/portfolio.php', array('courseid'=>$courseid))); 00071 $instance = portfolio_instance($config); 00072 $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id)); 00073 if ($mform->is_cancelled()){ 00074 redirect($baseurl); 00075 exit; 00076 } else if ($fromform = $mform->get_data()){ 00077 if (!confirm_sesskey()) { 00078 print_error('confirmsesskeybad', '', $baseurl); 00079 } 00080 //this branch is where you process validated data. 00081 $success = $instance->set_user_config($fromform, $USER->id); 00082 //$success = $success && $instance->save(); 00083 if ($success) { 00084 redirect($baseurl, get_string('instancesaved', 'portfolio'), 3); 00085 } else { 00086 print_error('instancenotsaved', 'portfolio', $baseurl); 00087 } 00088 exit; 00089 } else { 00090 echo $OUTPUT->heading(get_string('configplugin', 'portfolio')); 00091 echo $OUTPUT->box_start(); 00092 $mform->display(); 00093 echo $OUTPUT->box_end(); 00094 $display = false; 00095 } 00096 00097 } else if (!empty($hide)) { 00098 $instance = portfolio_instance($hide); 00099 $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id); 00100 } 00101 00102 if ($display) { 00103 echo $OUTPUT->heading($configstr); 00104 echo $OUTPUT->box_start(); 00105 00106 if (!$instances = portfolio_instances(true, false)) { 00107 print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php'); 00108 } 00109 00110 $table = new html_table(); 00111 $table->head = array($namestr, $pluginstr, ''); 00112 $table->data = array(); 00113 00114 foreach ($instances as $i) { 00115 $visible = $i->get_user_config('visible', $USER->id); 00116 $table->data[] = array($i->get('name'), $i->get('plugin'), 00117 ($i->has_user_config() 00118 ? '<a href="' . $baseurl . '?config=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" alt="' . get_string('configure') . '" /></a>' : '') . 00119 ' <a href="' . $baseurl . '?hide=' . $i->get('id') . '"><img src="' . $OUTPUT->pix_url('t/' . (($visible) ? 'hide' : 'show')) . '" alt="' . get_string($visible ? 'hide' : 'show') . '" /></a><br />' 00120 ); 00121 } 00122 00123 echo html_writer::table($table); 00124 echo $OUTPUT->box_end(); 00125 } 00126 echo $OUTPUT->footer(); 00127