2008-09-02 08:58:53 +00:00
|
|
|
<?php
|
2009-11-01 11:14:50 +00:00
|
|
|
|
2008-09-02 08:58:53 +00:00
|
|
|
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
|
|
|
require_once($CFG->dirroot . '/repository/lib.php');
|
|
|
|
require_once($CFG->libdir . '/adminlib.php');
|
|
|
|
|
|
|
|
// id of repository
|
|
|
|
$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);
|
2008-09-16 09:08:36 +00:00
|
|
|
$type = optional_param('type', '', PARAM_ALPHAEXT);
|
2008-09-02 08:58:53 +00:00
|
|
|
|
2008-09-05 06:30:18 +00:00
|
|
|
$context = get_context_instance(CONTEXT_SYSTEM);
|
|
|
|
|
2008-09-02 08:58:53 +00:00
|
|
|
$pagename = 'repositorycontroller';
|
|
|
|
|
2008-09-04 07:36:53 +00:00
|
|
|
if ($edit){
|
|
|
|
$pagename = 'repositoryinstanceedit';
|
2008-09-16 09:08:36 +00:00
|
|
|
} else if ($delete) {
|
2008-09-02 08:58:53 +00:00
|
|
|
$pagename = 'repositorydelete';
|
|
|
|
} else if ($new) {
|
2008-09-04 07:36:53 +00:00
|
|
|
$pagename = 'repositoryinstancenew';
|
2008-09-02 08:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
admin_externalpage_setup($pagename);
|
|
|
|
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
|
|
|
|
2009-01-01 14:25:29 +00:00
|
|
|
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?sesskey=" . sesskey();
|
2010-04-30 08:03:32 +00:00
|
|
|
$baseurl = "$CFG->wwwroot/$CFG->admin/repository.php?session=". sesskey() .'&action=edit&repos=';
|
2008-09-02 08:58:53 +00:00
|
|
|
if ($new) {
|
|
|
|
$baseurl .= $new;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$baseurl .= $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
$return = true;
|
|
|
|
|
|
|
|
if (!empty($edit) || !empty($new)) {
|
|
|
|
if (!empty($edit)) {
|
2008-11-26 07:03:10 +00:00
|
|
|
$instance = repository::get_instance($edit);
|
2009-06-04 06:40:35 +00:00
|
|
|
$instancetype = repository::get_type_by_id($instance->options['typeid']);
|
2008-09-02 08:58:53 +00:00
|
|
|
$classname = 'repository_' . $instancetype->get_typename();
|
|
|
|
$configs = $instance->get_instance_option_names();
|
|
|
|
$plugin = $instancetype->get_typename();
|
2009-06-04 06:40:35 +00:00
|
|
|
$typeid = $instance->options['typeid'];
|
2008-09-02 08:58:53 +00:00
|
|
|
} else {
|
|
|
|
$plugin = $new;
|
|
|
|
$typeid = $new;
|
|
|
|
$instance = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// display the edit form for this instance
|
2010-04-30 08:03:32 +00:00
|
|
|
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid, 'instance' => $instance, 'contextid' => $context->id));
|
2008-09-02 08:58:53 +00:00
|
|
|
// end setup, begin output
|
|
|
|
|
|
|
|
if ($mform->is_cancelled()){
|
|
|
|
redirect($baseurl);
|
|
|
|
exit;
|
|
|
|
} else if ($fromform = $mform->get_data()){
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
|
|
|
if ($edit) {
|
|
|
|
$settings = array();
|
|
|
|
$settings['name'] = $fromform->name;
|
2008-09-19 06:43:06 +00:00
|
|
|
if (!$instance->readonly) {
|
|
|
|
foreach($configs as $config) {
|
|
|
|
$settings[$config] = $fromform->$config;
|
|
|
|
}
|
2008-09-02 08:58:53 +00:00
|
|
|
}
|
|
|
|
$success = $instance->set_option($settings);
|
|
|
|
} else {
|
2008-11-26 07:03:10 +00:00
|
|
|
$success = repository::static_function($plugin, 'create', $plugin, 0, get_system_context(), $fromform);
|
2008-09-02 08:58:53 +00:00
|
|
|
$data = data_submitted();
|
|
|
|
}
|
|
|
|
if ($success) {
|
2010-04-11 09:41:25 +00:00
|
|
|
redirect($baseurl);
|
2008-09-02 08:58:53 +00:00
|
|
|
} else {
|
|
|
|
print_error('instancenotsaved', 'repository', $baseurl);
|
|
|
|
}
|
|
|
|
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', 'repository_'.$plugin));
|
2009-08-14 08:08:01 +00:00
|
|
|
echo $OUTPUT->box_start();
|
2008-09-02 08:58:53 +00:00
|
|
|
$mform->display();
|
2009-08-14 08:08:01 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2008-09-02 08:58:53 +00:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
} else if (!empty($hide)) {
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
2008-11-26 07:03:10 +00:00
|
|
|
$instance = repository::get_type_by_typename($hide);
|
2008-09-02 08:58:53 +00:00
|
|
|
$instance->hide();
|
|
|
|
$return = true;
|
2008-11-26 07:03:10 +00:00
|
|
|
} else if (!empty($delete)) {
|
|
|
|
$instance = repository::get_instance($delete);
|
2008-09-16 09:08:36 +00:00
|
|
|
//if you try to delete an instance set as readonly, display an error message
|
|
|
|
if ($instance->readonly) {
|
|
|
|
throw new repository_exception('readonlyinstance', 'repository');
|
|
|
|
}
|
2008-09-02 08:58:53 +00:00
|
|
|
if ($sure) {
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
|
|
|
if ($instance->delete()) {
|
|
|
|
$deletedstr = get_string('instancedeleted', 'repository');
|
|
|
|
redirect($baseurl, $deletedstr, 3);
|
|
|
|
} else {
|
|
|
|
print_error('instancenotdeleted', 'repository', $baseurl);
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
2009-08-20 08:39:07 +00:00
|
|
|
|
2010-04-30 08:03:32 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-20 08:39:07 +00:00
|
|
|
echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), "$sesskeyurl&type=$type'&delete=$delete'&sure=yes", "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?session=". sesskey());
|
2008-09-02 08:58:53 +00:00
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($return)) {
|
2008-11-26 07:03:10 +00:00
|
|
|
|
2008-09-02 08:58:53 +00:00
|
|
|
redirect($baseurl);
|
|
|
|
}
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|