3 require_once(dirname(dirname(__FILE__
)) . '/config.php');
4 require_once($CFG->dirroot
. '/repository/lib.php');
5 require_once($CFG->libdir
. '/adminlib.php');
8 $edit = optional_param('edit', 0, PARAM_INT
);
9 $new = optional_param('new', '', PARAM_FORMAT
);
10 $hide = optional_param('hide', 0, PARAM_INT
);
11 $delete = optional_param('delete', 0, PARAM_INT
);
12 $sure = optional_param('sure', '', PARAM_ALPHA
);
13 $type = optional_param('type', '', PARAM_PLUGIN
);
15 $context = get_context_instance(CONTEXT_SYSTEM
);
17 $pagename = 'repositorycontroller';
20 $pagename = 'repositoryinstanceedit';
22 $pagename = 'repositorydelete';
24 $pagename = 'repositoryinstancenew';
27 admin_externalpage_setup($pagename);
28 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
));
30 $sesskeyurl = "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?sesskey=" . sesskey();
31 $baseurl = "$CFG->wwwroot/$CFG->admin/repository.php?session=". sesskey() .'&action=edit&repos=';
41 if (!empty($edit) ||
!empty($new)) {
43 $instance = repository
::get_instance($edit);
44 $instancetype = repository
::get_type_by_id($instance->options
['typeid']);
45 $classname = 'repository_' . $instancetype->get_typename();
46 $configs = $instance->get_instance_option_names();
47 $plugin = $instancetype->get_typename();
48 $typeid = $instance->options
['typeid'];
55 // display the edit form for this instance
56 $mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid, 'instance' => $instance, 'contextid' => $context->id
));
57 // end setup, begin output
59 if ($mform->is_cancelled()){
62 } else if ($fromform = $mform->get_data()){
63 if (!confirm_sesskey()) {
64 print_error('confirmsesskeybad', '', $baseurl);
68 $settings['name'] = $fromform->name
;
69 if (!$instance->readonly
) {
70 foreach($configs as $config) {
71 if (isset($fromform->$config)) {
72 $settings[$config] = $fromform->$config;
74 $settings[$config] = null;
78 $success = $instance->set_option($settings);
80 $success = repository
::static_function($plugin, 'create', $plugin, 0, get_system_context(), $fromform);
81 $data = data_submitted();
86 print_error('instancenotsaved', 'repository', $baseurl);
90 echo $OUTPUT->header();
91 echo $OUTPUT->heading(get_string('configplugin', 'repository_'.$plugin));
92 echo $OUTPUT->box_start();
94 echo $OUTPUT->box_end();
97 } else if (!empty($hide)) {
98 if (!confirm_sesskey()) {
99 print_error('confirmsesskeybad', '', $baseurl);
101 $instance = repository
::get_type_by_typename($hide);
104 } else if (!empty($delete)) {
105 $instance = repository
::get_instance($delete);
106 //if you try to delete an instance set as readonly, display an error message
107 if ($instance->readonly
) {
108 throw new repository_exception('readonlyinstance', 'repository');
111 if (!confirm_sesskey()) {
112 print_error('confirmsesskeybad', '', $baseurl);
114 if ($instance->delete()) {
115 $deletedstr = get_string('instancedeleted', 'repository');
116 redirect($baseurl, $deletedstr, 3);
118 print_error('instancenotdeleted', 'repository', $baseurl);
123 echo $OUTPUT->header();
124 echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name
), "$sesskeyurl&type=$type'&delete=$delete'&sure=yes", "$CFG->wwwroot/$CFG->admin/repositoryinstance.php?session=". sesskey());
128 if (!empty($return)) {
132 echo $OUTPUT->footer();