2008-07-25 08:14:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
|
|
|
require_once($CFG->libdir . '/portfoliolib.php');
|
2009-12-12 11:27:07 +00:00
|
|
|
require_once($CFG->libdir . '/portfolio/forms.php');
|
2008-07-25 08:14:11 +00:00
|
|
|
require_once($CFG->libdir . '/adminlib.php');
|
|
|
|
|
2010-06-28 06:02:55 +00:00
|
|
|
$portfolio = optional_param('pf', '', PARAM_FORMAT);
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
$sure = optional_param('sure', '', PARAM_ALPHA);
|
2008-07-25 08:14:11 +00:00
|
|
|
|
|
|
|
$display = true; // fall through to normal display
|
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
$pagename = 'portfoliocontroller';
|
|
|
|
|
2010-06-28 06:02:55 +00:00
|
|
|
if ($action == 'edit') {
|
|
|
|
$pagename = 'portfoliosettings' . $portfolio;
|
|
|
|
} else if ($action == 'delete') {
|
2008-07-29 10:51:18 +00:00
|
|
|
$pagename = 'portfoliodelete';
|
2010-06-28 06:02:55 +00:00
|
|
|
} else if (($action == 'newon') || ($action == 'newoff')) {
|
2008-07-29 10:51:18 +00:00
|
|
|
$pagename = 'portfolionew';
|
|
|
|
}
|
2010-06-28 06:02:55 +00:00
|
|
|
|
|
|
|
// Need to remember this for form
|
|
|
|
$formaction = $action;
|
|
|
|
|
|
|
|
// Check what visibility to show the new repository
|
|
|
|
if ($action == 'newon') {
|
|
|
|
$action = 'new';
|
|
|
|
$visible = 1;
|
|
|
|
} else if ($action == 'newoff') {
|
|
|
|
$action = 'new';
|
|
|
|
$visible = 0;
|
|
|
|
}
|
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
admin_externalpage_setup($pagename);
|
2008-07-25 08:14:11 +00:00
|
|
|
|
2010-06-28 06:02:55 +00:00
|
|
|
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
|
|
|
|
2009-01-01 14:25:29 +00:00
|
|
|
$baseurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageportfolios";
|
|
|
|
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/portfolio.php?sesskey=" . sesskey();
|
|
|
|
$configstr = get_string('manageportfolios', 'portfolio');
|
2008-07-25 08:14:11 +00:00
|
|
|
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = true; // direct back to the main page
|
|
|
|
|
2010-06-28 06:02:55 +00:00
|
|
|
if (($action == 'edit') || ($action == 'new')) {
|
|
|
|
if (($action == 'edit')) {
|
|
|
|
$instance = portfolio_instance($portfolio);
|
2008-07-25 08:14:11 +00:00
|
|
|
$plugin = $instance->get('plugin');
|
2010-06-28 06:02:55 +00:00
|
|
|
|
|
|
|
// Since visible is being passed to form
|
|
|
|
// and used to set the value when a new
|
|
|
|
// instance is created - we must also
|
|
|
|
// place the currently visibility into the
|
|
|
|
// form as well
|
|
|
|
$visible = $instance->get('visible');
|
2008-07-25 08:14:11 +00:00
|
|
|
} else {
|
|
|
|
$instance = null;
|
2010-06-28 06:02:55 +00:00
|
|
|
$plugin = $portfolio;
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
2009-05-06 08:43:51 +00:00
|
|
|
|
|
|
|
$PAGE->set_pagetype('admin-portfolio-' . $plugin);
|
|
|
|
|
2010-06-28 06:02:55 +00:00
|
|
|
// Display the edit form for this instance
|
|
|
|
$mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance, 'portfolio' => $portfolio, 'action' => $formaction, 'visible' => $visible));
|
|
|
|
// End setup, begin output
|
2008-07-25 08:14:11 +00:00
|
|
|
if ($mform->is_cancelled()){
|
|
|
|
redirect($baseurl);
|
|
|
|
exit;
|
2010-06-28 06:02:55 +00:00
|
|
|
} else if (($fromform = $mform->get_data()) && (confirm_sesskey())) {
|
|
|
|
// Unset whatever doesn't belong in fromform
|
|
|
|
foreach (array('pf', 'action', 'plugin', 'sesskey', 'submitbutton') as $key) {
|
2008-08-20 13:30:37 +00:00
|
|
|
unset($fromform->{$key});
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
2010-06-28 06:02:55 +00:00
|
|
|
// This branch is where you process validated data.
|
|
|
|
if ($action == 'edit') {
|
2010-09-17 10:27:26 +00:00
|
|
|
$instance->set_config((array)$fromform);
|
2008-08-20 13:30:37 +00:00
|
|
|
$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');
|
2010-06-28 06:02:55 +00:00
|
|
|
redirect($baseurl, $savedstr, 1);
|
2008-07-25 08:14:11 +00:00
|
|
|
exit;
|
|
|
|
} else {
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->box_start();
|
2008-07-25 08:14:11 +00:00
|
|
|
$mform->display();
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = false;
|
2008-07-25 08:14:11 +00:00
|
|
|
}
|
2010-06-28 06:02:55 +00:00
|
|
|
} else if (($action == 'hide') || ($action == 'show')) {
|
|
|
|
require_sesskey();
|
|
|
|
|
|
|
|
$instance = portfolio_instance($portfolio);
|
2008-07-25 08:14:11 +00:00
|
|
|
$current = $instance->get('visible');
|
|
|
|
if (empty($current) && $instance->instance_sanity_check()) {
|
|
|
|
print_error('cannotsetvisible', 'portfolio', $baseurl);
|
|
|
|
}
|
2010-06-28 06:02:55 +00:00
|
|
|
|
|
|
|
if ($action == 'show') {
|
|
|
|
$visible = 1;
|
|
|
|
} else {
|
|
|
|
$visible = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance->set('visible', $visible);
|
2008-07-25 08:14:11 +00:00
|
|
|
$instance->save();
|
2008-07-29 10:51:18 +00:00
|
|
|
$return = true;
|
2010-06-28 06:02:55 +00:00
|
|
|
} else if ($action == 'delete') {
|
|
|
|
$instance = portfolio_instance($portfolio);
|
2008-07-25 08:14:11 +00:00
|
|
|
if ($sure) {
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
|
|
|
if ($instance->delete()) {
|
|
|
|
$deletedstr = get_string('instancedeleted', 'portfolio');
|
2010-06-28 06:02:55 +00:00
|
|
|
redirect($baseurl, $deletedstr, 1);
|
2008-07-25 08:14:11 +00:00
|
|
|
} else {
|
|
|
|
print_error('instancenotdeleted', 'portfolio', $baseurl);
|
|
|
|
}
|
|
|
|
exit;
|
2010-06-28 06:02:55 +00:00
|
|
|
} else {
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->confirm(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&pf='.$portfolio.'&action=delete&sure=yes', $baseurl);
|
|
|
|
$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
|
|
|
}
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-11-01 10:57:00 +00:00
|
|
|
|