2008-07-25 08:14:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
|
|
|
require_once($CFG->libdir . '/portfoliolib.php');
|
|
|
|
require_once($CFG->libdir . '/adminlib.php');
|
|
|
|
|
|
|
|
|
2008-07-28 11:33:51 +00:00
|
|
|
$CFG->pagepath = 'admin/manageportfolio';
|
|
|
|
|
2008-07-25 08:14:11 +00:00
|
|
|
$edit = optional_param('edit', 0, PARAM_INT);
|
|
|
|
$new = optional_param('new', '', PARAM_FORMAT);
|
|
|
|
$hide = optional_param('hide', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
|
|
|
$sure = optional_param('sure', '', PARAM_ALPHA);
|
|
|
|
|
|
|
|
$display = true; // fall through to normal display
|
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
$pagename = 'portfoliocontroller';
|
|
|
|
|
|
|
|
if ($edit) {
|
|
|
|
$pagename = 'portfoliosettings' . $edit;
|
|
|
|
} else if ($delete) {
|
|
|
|
$pagename = 'portfoliodelete';
|
|
|
|
} else if ($new) {
|
|
|
|
$pagename = 'portfolionew';
|
|
|
|
}
|
|
|
|
admin_externalpage_setup($pagename);
|
2008-07-25 08:14:11 +00:00
|
|
|
require_login(SITEID, false);
|
|
|
|
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
$baseurl = $CFG->wwwroot . '/admin/settings.php?section=manageportfolios';
|
2008-07-25 08:14:11 +00:00
|
|
|
$sesskeyurl = $CFG->wwwroot . '/' . $CFG->admin . '/portfolio.php?sesskey=' . sesskey();
|
|
|
|
$configstr = get_string('manageportfolios', 'portfolio');
|
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = true; // direct back to the main page
|
|
|
|
|
2008-07-25 08:14:11 +00:00
|
|
|
if (!empty($edit) || !empty($new)) {
|
|
|
|
if (!empty($edit)) {
|
|
|
|
$instance = portfolio_instance($edit);
|
|
|
|
$plugin = $instance->get('plugin');
|
|
|
|
} else {
|
|
|
|
$plugin = $new;
|
|
|
|
$instance = null;
|
|
|
|
}
|
2008-07-28 11:33:51 +00:00
|
|
|
$CFG->pagepath = 'admin/manageportfolio/' . $plugin;
|
2008-07-25 08:14:11 +00:00
|
|
|
// display the edit form for this instance
|
|
|
|
$mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance));
|
|
|
|
// end setup, begin output
|
|
|
|
if ($mform->is_cancelled()){
|
|
|
|
redirect($baseurl);
|
|
|
|
exit;
|
|
|
|
} else if ($fromform = $mform->get_data()){
|
2008-08-20 13:30:37 +00:00
|
|
|
// unset whatever doesn't belong in fromform
|
|
|
|
foreach (array('edit', 'new', 'plugin', 'sesskey', 'submitbutton') as $key) {
|
|
|
|
unset($fromform->{$key});
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
|
|
|
//this branch is where you process validated data.
|
|
|
|
if ($edit) {
|
2008-08-20 13:30:37 +00:00
|
|
|
$instance->set_config($fromform);
|
|
|
|
$instance->save();
|
2008-07-25 08:14:11 +00:00
|
|
|
} else {
|
2008-08-20 13:30:37 +00:00
|
|
|
portfolio_static_function($plugin, 'create_instance', $plugin, $fromform->name, $fromform);
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
2008-08-20 13:30:37 +00:00
|
|
|
$savedstr = get_string('instancesaved', 'portfolio');
|
|
|
|
admin_externalpage_print_header();
|
|
|
|
print_heading($savedstr);
|
|
|
|
redirect($baseurl, $savedstr, 3);
|
2008-07-25 08:14:11 +00:00
|
|
|
exit;
|
|
|
|
} else {
|
|
|
|
admin_externalpage_print_header();
|
|
|
|
print_heading(get_string('configplugin', 'portfolio'));
|
|
|
|
print_simple_box_start();
|
|
|
|
$mform->display();
|
|
|
|
print_simple_box_end();
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = false;
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
|
|
|
} else if (!empty($hide)) {
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
|
|
|
$instance = portfolio_instance($hide);
|
|
|
|
$current = $instance->get('visible');
|
|
|
|
if (empty($current) && $instance->instance_sanity_check()) {
|
|
|
|
print_error('cannotsetvisible', 'portfolio', $baseurl);
|
|
|
|
}
|
|
|
|
$instance->set('visible', !$instance->get('visible'));
|
|
|
|
$instance->save();
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = true;
|
2008-07-25 08:14:11 +00:00
|
|
|
} else if (!empty($delete)) {
|
|
|
|
admin_externalpage_print_header();
|
|
|
|
$instance = portfolio_instance($delete);
|
|
|
|
if ($sure) {
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
|
|
|
if ($instance->delete()) {
|
|
|
|
$deletedstr = get_string('instancedeleted', 'portfolio');
|
|
|
|
print_heading($deletedstr);
|
|
|
|
redirect($baseurl, $deletedstr, 3);
|
|
|
|
} else {
|
|
|
|
print_error('instancenotdeleted', 'portfolio', $baseurl);
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
notice_yesno(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&delete=' . $delete . '&sure=yes', $baseurl);
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = false;
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
if (!empty($return)) {
|
|
|
|
// normal display. fall through to here (don't call exit) if you want this to run
|
|
|
|
redirect($baseurl);
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
2008-07-29 10:51:18 +00:00
|
|
|
admin_externalpage_print_footer();
|
2008-07-25 08:14:11 +00:00
|
|
|
?>
|