MDL-26243 calendar: display correct number of repeated events
[moodle.git] / admin / repositoryinstance.php
blobe75193d0be4eee6ce21fdefd9f8d7ee64945e9f1
1 <?php
3 require_once(dirname(dirname(__FILE__)) . '/config.php');
4 require_once($CFG->dirroot . '/repository/lib.php');
5 require_once($CFG->libdir . '/adminlib.php');
7 // id of repository
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';
19 if ($edit){
20 $pagename = 'repositoryinstanceedit';
21 } else if ($delete) {
22 $pagename = 'repositorydelete';
23 } else if ($new) {
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=';
32 if ($new) {
33 $baseurl .= $new;
35 else {
36 $baseurl .= $type;
39 $return = true;
41 if (!empty($edit) || !empty($new)) {
42 if (!empty($edit)) {
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'];
49 } else {
50 $plugin = $new;
51 $typeid = $new;
52 $instance = null;
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()){
60 redirect($baseurl);
61 exit;
62 } else if ($fromform = $mform->get_data()){
63 if (!confirm_sesskey()) {
64 print_error('confirmsesskeybad', '', $baseurl);
66 if ($edit) {
67 $settings = array();
68 $settings['name'] = $fromform->name;
69 if (!$instance->readonly) {
70 foreach($configs as $config) {
71 if (isset($fromform->$config)) {
72 $settings[$config] = $fromform->$config;
73 } else {
74 $settings[$config] = null;
78 $success = $instance->set_option($settings);
79 } else {
80 $success = repository::static_function($plugin, 'create', $plugin, 0, get_system_context(), $fromform);
81 $data = data_submitted();
83 if ($success) {
84 redirect($baseurl);
85 } else {
86 print_error('instancenotsaved', 'repository', $baseurl);
88 exit;
89 } else {
90 echo $OUTPUT->header();
91 echo $OUTPUT->heading(get_string('configplugin', 'repository_'.$plugin));
92 echo $OUTPUT->box_start();
93 $mform->display();
94 echo $OUTPUT->box_end();
95 $return = false;
97 } else if (!empty($hide)) {
98 if (!confirm_sesskey()) {
99 print_error('confirmsesskeybad', '', $baseurl);
101 $instance = repository::get_type_by_typename($hide);
102 $instance->hide();
103 $return = true;
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');
110 if ($sure) {
111 if (!confirm_sesskey()) {
112 print_error('confirmsesskeybad', '', $baseurl);
114 if ($instance->delete()) {
115 $deletedstr = get_string('instancedeleted', 'repository');
116 redirect($baseurl, $deletedstr, 3);
117 } else {
118 print_error('instancenotdeleted', 'repository', $baseurl);
120 exit;
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());
125 $return = false;
128 if (!empty($return)) {
130 redirect($baseurl);
132 echo $OUTPUT->footer();