if (!empty($edit) || !empty($new)) {
if (!empty($edit)) {
$instance = repository_get_instance($edit);
- //if you try to edit an instance set as readonly, display an error message
- if ($instance->readonly) {
- throw new repository_exception('readonlyinstance', 'repository');
- }
$instancetype = repository_get_type_by_id($instance->typeid);
$classname = 'repository_' . $instancetype->get_typename();
$configs = $instance->get_instance_option_names();
if ($edit) {
$settings = array();
$settings['name'] = $fromform->name;
- foreach($configs as $config) {
- $settings[$config] = $fromform->$config;
+ if (!$instance->readonly) {
+ foreach($configs as $config) {
+ $settings[$config] = $fromform->$config;
+ }
}
$success = $instance->set_option($settings);
} else {
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
$mform->addRule('name', $strrequired, 'required', null, 'client');
- //add fields
- if (!$this->instance) {
- $result = repository_static_function($this->plugin, 'instance_config_form', $mform);
- } else {
- $result = $this->instance->instance_config_form($mform);
- }
-
- // and set the data if we have some.
- if ($this->instance) {
- $data = array();
- $data['name'] = $this->instance->name;
- foreach ($this->instance->get_instance_option_names() as $config) {
- if (!empty($this->instance->$config)) {
- $data[$config] = $this->instance->$config;
- } else {
- $data[$config] = '';
+ if (!$this->instance->readonly) {
+ //add fields
+ if (!$this->instance) {
+ $result = repository_static_function($this->plugin, 'instance_config_form', $mform);
+ } else {
+ $result = $this->instance->instance_config_form($mform);
+ }
+
+ // and set the data if we have some.
+ if ($this->instance) {
+ $data = array();
+ $data['name'] = $this->instance->name;
+ foreach ($this->instance->get_instance_option_names() as $config) {
+ if (!empty($this->instance->$config)) {
+ $data[$config] = $this->instance->$config;
+ } else {
+ $data[$config] = '';
+ }
}
+ $this->set_data($data);
}
- $this->set_data($data);
}
+ else {
+ if ($this->instance) {
+ $data = array();
+ $data['name'] = $this->instance->name;
+ $this->set_data($data);
+ }
+ }
+
$this->add_action_buttons(true, get_string('save','repository'));
}
foreach ($instances as $i) {
$settings = '';
$delete = '';
+ $settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
if (!$i->readonly) {
- $settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
$delete .= '<a href="' . $baseurl . '&type='.$typename.'&delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
}