2008-09-02 08:58:53 +00:00
|
|
|
<?php
|
2009-11-01 11:14:50 +00:00
|
|
|
|
2008-08-13 04:09:13 +00:00
|
|
|
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
|
|
|
require_once($CFG->dirroot . '/repository/lib.php');
|
|
|
|
require_once($CFG->libdir . '/adminlib.php');
|
|
|
|
|
2010-04-30 08:03:32 +00:00
|
|
|
$repository = optional_param('repos', '', PARAM_FORMAT);
|
|
|
|
$action = optional_param('action', '', PARAM_ALPHA);
|
|
|
|
$sure = optional_param('sure', '', PARAM_ALPHA);
|
2008-08-13 04:09:13 +00:00
|
|
|
|
|
|
|
$display = true; // fall through to normal display
|
|
|
|
|
2010-11-08 17:12:03 +00:00
|
|
|
$pagename = 'managerepositories';
|
2008-08-13 04:09:13 +00:00
|
|
|
|
2010-04-30 08:03:32 +00:00
|
|
|
if ($action == 'edit') {
|
|
|
|
$pagename = 'repositorysettings' . $repository;
|
|
|
|
} else if ($action == 'delete') {
|
2008-08-13 04:09:13 +00:00
|
|
|
$pagename = 'repositorydelete';
|
2010-04-30 08:03:32 +00:00
|
|
|
} else if (($action == 'newon') || ($action == 'newoff')) {
|
2008-08-13 04:09:13 +00:00
|
|
|
$pagename = 'repositorynew';
|
|
|
|
}
|
2008-08-19 03:56:52 +00:00
|
|
|
|
2010-04-30 08:03:32 +00:00
|
|
|
// Need to remember this for form
|
|
|
|
$formaction = $action;
|
|
|
|
|
|
|
|
// Check what visibility to show the new repository
|
|
|
|
if ($action == 'newon') {
|
|
|
|
$action = 'new';
|
|
|
|
$visible = true;
|
|
|
|
} else if ($action == 'newoff') {
|
|
|
|
$action = 'new';
|
|
|
|
$visible = false;
|
|
|
|
}
|
|
|
|
|
2008-08-13 04:09:13 +00:00
|
|
|
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
2010-03-04 06:44:16 +00:00
|
|
|
admin_externalpage_setup($pagename);
|
2008-08-13 04:09:13 +00:00
|
|
|
|
2010-03-09 08:18:04 +00:00
|
|
|
$sesskeyurl = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php?sesskey=' . sesskey();
|
2010-11-08 17:12:03 +00:00
|
|
|
$baseurl = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php';
|
2010-03-04 06:44:16 +00:00
|
|
|
|
2010-04-11 09:41:25 +00:00
|
|
|
$configstr = get_string('manage', 'repository');
|
2008-08-13 04:09:13 +00:00
|
|
|
|
|
|
|
$return = true;
|
|
|
|
|
2010-11-08 17:12:03 +00:00
|
|
|
/**
|
|
|
|
* Helper function that generates a moodle_url object
|
|
|
|
* relevant to the repository
|
|
|
|
*/
|
|
|
|
function repository_action_url($repository) {
|
|
|
|
global $baseurl;
|
|
|
|
return new moodle_url($baseurl, array('sesskey'=>sesskey(), 'repos'=>$repository));
|
|
|
|
}
|
|
|
|
|
2010-04-30 08:03:32 +00:00
|
|
|
if (($action == 'edit') || ($action == 'new')) {
|
2010-07-27 09:03:54 +00:00
|
|
|
$pluginname = '';
|
2010-04-30 08:03:32 +00:00
|
|
|
if ($action == 'edit') {
|
|
|
|
$repositorytype = repository::get_type_by_typename($repository);
|
2008-09-02 08:58:53 +00:00
|
|
|
$classname = 'repository_' . $repositorytype->get_typename();
|
2010-07-27 09:03:54 +00:00
|
|
|
$configs = call_user_func(array($classname, 'get_type_option_names'));
|
2008-09-02 08:58:53 +00:00
|
|
|
$plugin = $repositorytype->get_typename();
|
2010-07-27 09:03:54 +00:00
|
|
|
// looking for instance to edit plugin name
|
2010-08-03 07:16:33 +00:00
|
|
|
$instanceoptions = call_user_func(array($classname, 'get_instance_option_names'));
|
2010-07-27 09:03:54 +00:00
|
|
|
if (empty($instanceoptions)) {
|
|
|
|
$params = array();
|
|
|
|
$params['type'] = $plugin;
|
|
|
|
$instances = repository::get_instances($params);
|
|
|
|
if ($instance = array_pop($instances)) {
|
|
|
|
// use the one form db record
|
|
|
|
$pluginname = $instance->instance->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 04:09:13 +00:00
|
|
|
} else {
|
2010-03-09 08:18:04 +00:00
|
|
|
$repositorytype = null;
|
2010-04-30 08:03:32 +00:00
|
|
|
$plugin = $repository;
|
|
|
|
$typeid = $repository;
|
2008-08-13 04:09:13 +00:00
|
|
|
}
|
2009-05-06 08:43:51 +00:00
|
|
|
$PAGE->set_pagetype('admin-repository-' . $plugin);
|
2008-08-13 04:09:13 +00:00
|
|
|
// display the edit form for this instance
|
2010-07-27 09:03:54 +00:00
|
|
|
$mform = new repository_type_form('', array('pluginname'=>$pluginname, 'plugin' => $plugin, 'instance' => $repositorytype, 'action' => $formaction));
|
2008-09-05 06:30:18 +00:00
|
|
|
$fromform = $mform->get_data();
|
2008-09-18 02:36:17 +00:00
|
|
|
|
|
|
|
//detect if we create a new type without config (in this case if don't want to display a setting page during creation)
|
2010-03-09 08:18:04 +00:00
|
|
|
$nosettings = false;
|
2010-04-30 08:03:32 +00:00
|
|
|
if ($action == 'new') {
|
|
|
|
$adminconfignames = repository::static_function($repository, 'get_type_option_names');
|
2010-03-09 08:18:04 +00:00
|
|
|
$nosettings = empty($adminconfignames);
|
2008-09-18 02:36:17 +00:00
|
|
|
}
|
2008-08-13 04:09:13 +00:00
|
|
|
// end setup, begin output
|
2010-03-09 08:18:04 +00:00
|
|
|
|
2008-08-13 04:09:13 +00:00
|
|
|
if ($mform->is_cancelled()){
|
|
|
|
redirect($baseurl);
|
2010-03-09 08:18:04 +00:00
|
|
|
} else if (!empty($fromform) || $nosettings) {
|
2010-04-30 08:03:32 +00:00
|
|
|
require_sesskey();
|
|
|
|
if ($action == 'edit') {
|
2008-08-13 04:09:13 +00:00
|
|
|
$settings = array();
|
|
|
|
foreach($configs as $config) {
|
2009-06-30 09:10:42 +00:00
|
|
|
if (!empty($fromform->$config)) {
|
|
|
|
$settings[$config] = $fromform->$config;
|
2009-10-08 09:01:34 +00:00
|
|
|
} else {
|
|
|
|
// if the config name is not appear in $fromform
|
|
|
|
// empty this config value
|
|
|
|
$settings[$config] = '';
|
2009-06-30 09:10:42 +00:00
|
|
|
}
|
2008-08-13 04:09:13 +00:00
|
|
|
}
|
2010-04-30 08:03:32 +00:00
|
|
|
$instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
|
2008-10-09 03:02:26 +00:00
|
|
|
if (!empty($instanceoptionnames)) {
|
2009-10-08 09:01:34 +00:00
|
|
|
if (array_key_exists('enablecourseinstances', $fromform)) {
|
|
|
|
$settings['enablecourseinstances'] = $fromform->enablecourseinstances;
|
2008-10-09 03:02:26 +00:00
|
|
|
}
|
2009-10-08 09:01:34 +00:00
|
|
|
else {
|
|
|
|
$settings['enablecourseinstances'] = 0;
|
|
|
|
}
|
|
|
|
if (array_key_exists('enableuserinstances', $fromform)) {
|
|
|
|
$settings['enableuserinstances'] = $fromform->enableuserinstances;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$settings['enableuserinstances'] = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-09-02 08:58:53 +00:00
|
|
|
$success = $repositorytype->update_options($settings);
|
2008-08-13 04:09:13 +00:00
|
|
|
} else {
|
2010-04-30 08:03:32 +00:00
|
|
|
$type = new repository_type($plugin, (array)$fromform, $visible);
|
2008-09-02 08:58:53 +00:00
|
|
|
$type->create();
|
|
|
|
$success = true;
|
2008-08-13 04:09:13 +00:00
|
|
|
$data = data_submitted();
|
|
|
|
}
|
|
|
|
if ($success) {
|
2010-04-30 08:03:32 +00:00
|
|
|
// configs saved
|
|
|
|
redirect($baseurl);
|
2008-08-13 04:09:13 +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));
|
2008-09-19 09:56:53 +00:00
|
|
|
$displaysettingform = true;
|
2010-04-30 08:03:32 +00:00
|
|
|
if ($action == 'edit') {
|
|
|
|
$typeoptionnames = repository::static_function($repository, 'get_type_option_names');
|
|
|
|
$instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
|
2008-10-09 03:02:26 +00:00
|
|
|
if (empty($typeoptionnames) && empty($instanceoptionnames)) {
|
2008-09-19 09:56:53 +00:00
|
|
|
$displaysettingform = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($displaysettingform){
|
2009-07-09 07:17:18 +00:00
|
|
|
$OUTPUT->box_start();
|
2008-09-19 06:16:20 +00:00
|
|
|
$mform->display();
|
2009-07-09 07:17:18 +00:00
|
|
|
$OUTPUT->box_end();
|
2008-09-19 06:16:20 +00:00
|
|
|
}
|
2008-08-13 04:09:13 +00:00
|
|
|
$return = false;
|
2008-09-02 08:58:53 +00:00
|
|
|
|
2010-04-30 08:03:32 +00:00
|
|
|
// Display instances list and creation form
|
2010-07-27 09:03:54 +00:00
|
|
|
if ($action == 'edit') {
|
2010-04-30 08:03:32 +00:00
|
|
|
$instanceoptionnames = repository::static_function($repository, 'get_instance_option_names');
|
|
|
|
if (!empty($instanceoptionnames)) {
|
|
|
|
repository::display_instances_list(get_context_instance(CONTEXT_SYSTEM), $repository);
|
2008-09-04 02:15:30 +00:00
|
|
|
}
|
2008-09-02 08:58:53 +00:00
|
|
|
}
|
2008-08-13 04:09:13 +00:00
|
|
|
}
|
2010-04-30 08:03:32 +00:00
|
|
|
} else if ($action == 'show') {
|
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
|
|
|
$repositorytype = repository::get_type_by_typename($repository);
|
|
|
|
if (empty($repositorytype)) {
|
|
|
|
print_error('invalidplugin', 'repository', '', $repository);
|
|
|
|
}
|
|
|
|
$repositorytype->update_visibility(true);
|
|
|
|
$return = true;
|
|
|
|
} else if ($action == 'hide') {
|
2008-08-13 04:09:13 +00:00
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
2010-04-30 08:03:32 +00:00
|
|
|
$repositorytype = repository::get_type_by_typename($repository);
|
2009-03-05 05:40:56 +00:00
|
|
|
if (empty($repositorytype)) {
|
2010-04-30 08:03:32 +00:00
|
|
|
print_error('invalidplugin', 'repository', '', $repository);
|
2009-03-05 05:40:56 +00:00
|
|
|
}
|
2010-04-30 08:03:32 +00:00
|
|
|
$repositorytype->update_visibility(false);
|
2008-08-13 04:09:13 +00:00
|
|
|
$return = true;
|
2010-04-30 08:03:32 +00:00
|
|
|
} else if ($action == 'delete') {
|
|
|
|
$repositorytype = repository::get_type_by_typename($repository);
|
2008-08-13 04:09:13 +00:00
|
|
|
if ($sure) {
|
2010-04-30 08:03:32 +00:00
|
|
|
$PAGE->set_pagetype('admin-repository-' . $repository);
|
2008-08-13 04:09:13 +00:00
|
|
|
if (!confirm_sesskey()) {
|
|
|
|
print_error('confirmsesskeybad', '', $baseurl);
|
|
|
|
}
|
2008-09-02 08:58:53 +00:00
|
|
|
if ($repositorytype->delete()) {
|
2010-04-11 09:41:25 +00:00
|
|
|
redirect($baseurl);
|
2008-08-13 04:09:13 +00:00
|
|
|
} else {
|
|
|
|
print_error('instancenotdeleted', 'repository', $baseurl);
|
|
|
|
}
|
|
|
|
exit;
|
2010-03-04 06:44:16 +00:00
|
|
|
} else {
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2010-04-30 08:03:32 +00:00
|
|
|
echo $OUTPUT->confirm(get_string('confirmremove', 'repository', $repositorytype->get_readablename()), $sesskeyurl . '&action=delete&repos=' . $repository . '&sure=yes', $baseurl);
|
2010-03-04 06:44:16 +00:00
|
|
|
$return = false;
|
2008-08-13 04:09:13 +00:00
|
|
|
}
|
2010-04-30 08:03:32 +00:00
|
|
|
} else if ($action == 'moveup') {
|
|
|
|
$repositorytype = repository::get_type_by_typename($repository);
|
|
|
|
$repositorytype->move_order('up');
|
|
|
|
} else if ($action == 'movedown') {
|
|
|
|
$repositorytype = repository::get_type_by_typename($repository);
|
|
|
|
$repositorytype->move_order('down');
|
2010-11-08 17:12:03 +00:00
|
|
|
} else {
|
|
|
|
// If page is loaded directly
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->heading(get_string('manage', 'repository'));
|
|
|
|
|
|
|
|
// Get strings that are used
|
|
|
|
$strshow = get_string('on', 'repository');
|
|
|
|
$strhide = get_string('off', 'repository');
|
|
|
|
$strdelete = get_string('disabled', 'repository');
|
|
|
|
|
|
|
|
$actionchoicesforexisting = array(
|
|
|
|
'show' => $strshow,
|
|
|
|
'hide' => $strhide,
|
|
|
|
'delete' => $strdelete
|
|
|
|
);
|
|
|
|
|
|
|
|
$actionchoicesfornew = array(
|
|
|
|
'newon' => $strshow,
|
|
|
|
'newoff' => $strhide,
|
|
|
|
'delete' => $strdelete
|
|
|
|
);
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
$output .= $OUTPUT->box_start('generalbox');
|
|
|
|
|
|
|
|
// Set strings that are used multiple times
|
|
|
|
$settingsstr = get_string('settings');
|
|
|
|
$disablestr = get_string('disable');
|
|
|
|
|
|
|
|
// Table to list plug-ins
|
|
|
|
$table = new html_table();
|
|
|
|
$table->head = array(get_string('name'), get_string('isactive', 'repository'), get_string('order'), $settingsstr);
|
|
|
|
$table->align = array('left', 'center', 'center', 'center', 'center');
|
|
|
|
$table->data = array();
|
|
|
|
|
|
|
|
// Get list of used plug-ins
|
|
|
|
$instances = repository::get_types();
|
|
|
|
if (!empty($instances)) {
|
|
|
|
// Array to store plugins being used
|
|
|
|
$alreadyplugins = array();
|
|
|
|
$totalinstances = count($instances);
|
|
|
|
$updowncount = 1;
|
|
|
|
foreach ($instances as $i) {
|
|
|
|
$settings = '';
|
|
|
|
$typename = $i->get_typename();
|
|
|
|
// Display edit link only if you can config the type or if it has multiple instances (e.g. has instance config)
|
|
|
|
$typeoptionnames = repository::static_function($typename, 'get_type_option_names');
|
|
|
|
$instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
|
|
|
|
|
|
|
|
if (!empty($typeoptionnames) || !empty($instanceoptionnames)) {
|
|
|
|
// Calculate number of instances in order to display them for the Moodle administrator
|
|
|
|
if (!empty($instanceoptionnames)) {
|
|
|
|
$params = array();
|
|
|
|
$params['context'] = array(get_system_context());
|
|
|
|
$params['onlyvisible'] = false;
|
|
|
|
$params['type'] = $typename;
|
|
|
|
$admininstancenumber = count(repository::static_function($typename, 'get_instances', $params));
|
|
|
|
// site instances
|
|
|
|
$admininstancenumbertext = get_string('instancesforsite', 'repository', $admininstancenumber);
|
|
|
|
$params['context'] = array();
|
|
|
|
$instances = repository::static_function($typename, 'get_instances', $params);
|
|
|
|
$courseinstances = array();
|
|
|
|
$userinstances = array();
|
|
|
|
|
|
|
|
foreach ($instances as $instance) {
|
|
|
|
if ($instance->context->contextlevel == CONTEXT_COURSE) {
|
|
|
|
$courseinstances[] = $instance;
|
|
|
|
} else if ($instance->context->contextlevel == CONTEXT_USER) {
|
|
|
|
$userinstances[] = $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// course instances
|
|
|
|
$instancenumber = count($courseinstances);
|
|
|
|
$courseinstancenumbertext = get_string('instancesforcourses', 'repository', $instancenumber);
|
|
|
|
|
|
|
|
// user private instances
|
|
|
|
$instancenumber = count($userinstances);
|
|
|
|
$userinstancenumbertext = get_string('instancesforusers', 'repository', $instancenumber);
|
|
|
|
} else {
|
|
|
|
$admininstancenumbertext = "";
|
|
|
|
$courseinstancenumbertext = "";
|
|
|
|
$userinstancenumbertext = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
$settings .= '<a href="' . $sesskeyurl . '&action=edit&repos=' . $typename . '">' . $settingsstr .'</a>';
|
|
|
|
|
|
|
|
$settings .= $OUTPUT->container_start('mdl-left');
|
|
|
|
$settings .= '<br/>';
|
|
|
|
$settings .= $admininstancenumbertext;
|
|
|
|
$settings .= '<br/>';
|
|
|
|
$settings .= $courseinstancenumbertext;
|
|
|
|
$settings .= '<br/>';
|
|
|
|
$settings .= $userinstancenumbertext;
|
|
|
|
$settings .= $OUTPUT->container_end();
|
|
|
|
}
|
|
|
|
// Get the current visibility
|
|
|
|
if ($i->get_visible()) {
|
|
|
|
$currentaction = 'show';
|
|
|
|
} else {
|
|
|
|
$currentaction = 'hide';
|
|
|
|
}
|
|
|
|
|
|
|
|
$select = new single_select(repository_action_url($typename, 'repos'), 'action', $actionchoicesforexisting, $currentaction, null, 'applyto' . basename($typename));
|
2012-04-11 17:18:58 +12:00
|
|
|
|
2010-11-08 17:12:03 +00:00
|
|
|
// Display up/down link
|
|
|
|
$updown = '';
|
|
|
|
$spacer = $OUTPUT->spacer(array('height'=>15, 'width'=>15)); // should be done with CSS instead
|
|
|
|
|
|
|
|
if ($updowncount > 1) {
|
|
|
|
$updown .= "<a href=\"$sesskeyurl&action=moveup&repos=".$typename."\">";
|
|
|
|
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"up\" /></a> ";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$updown .= $spacer;
|
|
|
|
}
|
|
|
|
if ($updowncount < $totalinstances) {
|
|
|
|
$updown .= "<a href=\"$sesskeyurl&action=movedown&repos=".$typename."\">";
|
|
|
|
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"down\" /></a>";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$updown .= $spacer;
|
|
|
|
}
|
|
|
|
|
|
|
|
$updowncount++;
|
|
|
|
|
|
|
|
$table->data[] = array($i->get_readablename(), $OUTPUT->render($select), $updown, $settings);
|
|
|
|
|
|
|
|
if (!in_array($typename, $alreadyplugins)) {
|
|
|
|
$alreadyplugins[] = $typename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all the plugins that exist on disk
|
|
|
|
$plugins = get_plugin_list('repository');
|
|
|
|
if (!empty($plugins)) {
|
|
|
|
foreach ($plugins as $plugin => $dir) {
|
|
|
|
// Check that it has not already been listed
|
|
|
|
if (!in_array($plugin, $alreadyplugins)) {
|
|
|
|
$select = new single_select(repository_action_url($plugin, 'repos'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . basename($plugin));
|
|
|
|
$table->data[] = array(get_string('pluginname', 'repository_'.$plugin), $OUTPUT->render($select), '', '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= html_writer::table($table);
|
|
|
|
$output .= $OUTPUT->box_end();
|
|
|
|
print $output;
|
|
|
|
$return = false;
|
2008-09-02 08:58:53 +00:00
|
|
|
}
|
2008-08-13 04:09:13 +00:00
|
|
|
|
2010-11-08 17:12:03 +00:00
|
|
|
if ($return) {
|
2008-08-13 04:09:13 +00:00
|
|
|
redirect($baseurl);
|
|
|
|
}
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|