"MDL-13766, improve user instances list"
This commit is contained in:
@@ -89,7 +89,7 @@ $string['notyourinstances'] = 'You can not view/edit repository instances of ano
|
||||
$string['noresult'] = 'No search result';
|
||||
$string['operation'] = 'Operation';
|
||||
$string['openpicker'] = 'Choose a file...';
|
||||
$string['personalrepositories'] = 'Personal repositories';
|
||||
$string['personalrepositories'] = 'Avaiable repository instances';
|
||||
$string['plugin'] = 'Repository plug-ins';
|
||||
$string['pluginerror'] = 'Errors in repository plugin.';
|
||||
$string['preview'] = 'Preview';
|
||||
@@ -122,6 +122,7 @@ $string['updown'] = 'Display order';
|
||||
$string['upload'] = 'Upload this file';
|
||||
$string['uploading'] = 'Uploading...';
|
||||
$string['uploadsucc'] = 'The file has been uploaded successfully';
|
||||
$string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context';
|
||||
$string['wrongcontext'] = 'You cannot access to this context';
|
||||
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
|
||||
$string['ziped'] = 'Compress folder successfully';
|
||||
|
||||
+26
-9
@@ -95,16 +95,17 @@ class repository_type {
|
||||
* Return if the instance is visible in a context
|
||||
* TODO: check if the context visibility has been overwritten by the plugin creator
|
||||
* (need to create special functions to be overvwritten in repository class)
|
||||
* @param objet $contextlevel - context level
|
||||
* @param objet $context - context
|
||||
* @return boolean
|
||||
*/
|
||||
public function get_contextvisibility($contextlevel) {
|
||||
public function get_contextvisibility($context) {
|
||||
global $USER;
|
||||
|
||||
if ($contextlevel == CONTEXT_COURSE) {
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
return $this->_options['enablecourseinstances'];
|
||||
}
|
||||
|
||||
if ($contextlevel == CONTEXT_USER) {
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
return $this->_options['enableuserinstances'];
|
||||
}
|
||||
|
||||
@@ -577,7 +578,7 @@ abstract class repository {
|
||||
foreach ($types as $type) {
|
||||
$instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
|
||||
if (!empty($instanceoptionnames)) {
|
||||
if ($type->get_contextvisibility($context->contextlevel)) {
|
||||
if ($type->get_contextvisibility($context)) {
|
||||
$editabletypes[]=$type;
|
||||
}
|
||||
}
|
||||
@@ -1007,6 +1008,7 @@ abstract class repository {
|
||||
} else {
|
||||
$baseurl = $CFG->httpswwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&sesskey=' . sesskey();
|
||||
}
|
||||
$url = new moodle_url($baseurl);
|
||||
|
||||
$namestr = get_string('name');
|
||||
$pluginstr = get_string('plugin', 'repository');
|
||||
@@ -1036,9 +1038,24 @@ abstract class repository {
|
||||
foreach ($instances as $i) {
|
||||
$settings = '';
|
||||
$delete = '';
|
||||
$settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
|
||||
if (!$i->readonly) {
|
||||
$delete .= '<a href="' . $baseurl . '&type='.$typename.'&delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
|
||||
|
||||
$type = repository::get_type_by_id($i->options['typeid']);
|
||||
|
||||
if ($type->get_contextvisibility($context)) {
|
||||
if (!$i->readonly) {
|
||||
|
||||
$url->param('type', $i->options['type']);
|
||||
$url->param('edit', $i->id);
|
||||
$link = html_link::make($url->out(), $settingsstr);
|
||||
$settings .= $OUTPUT->link($link);
|
||||
|
||||
$url->remove_params('edit');
|
||||
$url->param('delete', $i->id);
|
||||
$link = html_link::make($url->out(), $deletestr);
|
||||
$delete .= $OUTPUT->link($link);
|
||||
|
||||
$url->remove_params('type');
|
||||
}
|
||||
}
|
||||
|
||||
$type = repository::get_type_by_id($i->options['typeid']);
|
||||
@@ -1161,7 +1178,7 @@ abstract class repository {
|
||||
|
||||
if ($type->get_visible()) {
|
||||
//if the instance is unique so it's visible, otherwise check if the instance has a enabled context
|
||||
if (empty($instanceoptions) || $type->get_contextvisibility($this->context->contextlevel)) {
|
||||
if (empty($instanceoptions) || $type->get_contextvisibility($this->context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+199
-172
@@ -1,209 +1,236 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->dirroot . '/repository/lib.php');
|
||||
//require_once($CFG->libdir . '/adminlib.php');
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
$edit = optional_param('edit', 0, PARAM_INT); // Repository ID
|
||||
$new = optional_param('new', '', PARAM_FORMAT);
|
||||
$delete = optional_param('delete', 0, PARAM_INT);
|
||||
$sure = optional_param('sure', '', PARAM_ALPHA);
|
||||
$contextid = optional_param('contextid', 0, PARAM_INT);
|
||||
$usercourseid = optional_param('usercourseid', SITEID, PARAM_INT); // Extra: used for user context only
|
||||
|
||||
$url = new moodle_url($CFG->wwwroot.'/repository/manage_instances.php');
|
||||
/**
|
||||
* This file is used to manage repositories
|
||||
*
|
||||
* @since 2.0
|
||||
* @package moodlecore
|
||||
* @subpackage repository
|
||||
* @copyright 2009 Dongsheng Cai <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
if ($edit){
|
||||
$url->param('edit', $edit);
|
||||
$pagename = 'repositoryinstanceedit';
|
||||
} else if ($delete) {
|
||||
$url->param('delete', $delete);
|
||||
$pagename = 'repositorydelete';
|
||||
} else if ($new) {
|
||||
$url->param('new', $new);
|
||||
$pagename = 'repositoryinstancenew';
|
||||
} else {
|
||||
$pagename = 'repositorylist';
|
||||
}
|
||||
require_once(dirname(dirname(__FILE__)) . '/config.php');
|
||||
require_once($CFG->dirroot . '/repository/lib.php');
|
||||
|
||||
if ($sure !== '') {
|
||||
$url->param('sure', $sure);
|
||||
}
|
||||
if ($contextid !== 0) {
|
||||
$url->param('contextid', $contextid);
|
||||
}
|
||||
if ($usercourseid !== SITEID) {
|
||||
$url->param('usercourseid', $usercourseid);
|
||||
}
|
||||
$edit = optional_param('edit', 0, PARAM_INT);
|
||||
$new = optional_param('new', '', PARAM_FORMAT);
|
||||
$delete = optional_param('delete', 0, PARAM_INT);
|
||||
$sure = optional_param('sure', '', PARAM_ALPHA);
|
||||
$contextid = optional_param('contextid', 0, PARAM_INT);
|
||||
$usercourseid = optional_param('usercourseid', SITEID, PARAM_INT); // Extra: used for user context only
|
||||
|
||||
$PAGE->set_url($url);
|
||||
$url = new moodle_url($CFG->wwwroot.'/repository/manage_instances.php');
|
||||
$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $contextid . '&sesskey='. sesskey();
|
||||
|
||||
require_login(SITEID, false);
|
||||
if ($edit){
|
||||
$url->param('edit', $edit);
|
||||
$pagename = 'repositoryinstanceedit';
|
||||
} else if ($delete) {
|
||||
$url->param('delete', $delete);
|
||||
$pagename = 'repositorydelete';
|
||||
} else if ($new) {
|
||||
$url->param('new', $new);
|
||||
$pagename = 'repositoryinstancenew';
|
||||
} else {
|
||||
$pagename = 'repositorylist';
|
||||
}
|
||||
|
||||
$context = get_context_instance_by_id($contextid);
|
||||
if ($sure !== '') {
|
||||
$url->param('sure', $sure);
|
||||
}
|
||||
if ($contextid !== 0) {
|
||||
$url->param('contextid', $contextid);
|
||||
}
|
||||
if ($usercourseid !== SITEID) {
|
||||
$url->param('usercourseid', $usercourseid);
|
||||
}
|
||||
|
||||
$PAGE->set_url($url);
|
||||
|
||||
require_login(SITEID, false);
|
||||
|
||||
$context = get_context_instance_by_id($contextid);
|
||||
|
||||
/// Security: make sure we're allowed to do this operation
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$pagename = get_string("repositorycourse",'repository');
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$pagename = get_string("repositorycourse",'repository');
|
||||
|
||||
// If the user is allowed to edit this course, he's allowed to edit list of repository instances
|
||||
require_capability('moodle/course:update', $context);
|
||||
// If the user is allowed to edit this course, he's allowed to edit list of repository instances
|
||||
require_capability('moodle/course:update', $context);
|
||||
|
||||
if ( !$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
} else if ($context->contextlevel == CONTEXT_USER) {
|
||||
$pagename = get_string("personalrepositories",'repository');
|
||||
//is the user looking at its own repository instances
|
||||
if ($USER->id != $context->instanceid){
|
||||
print_error('notyourinstances', 'repository');
|
||||
}
|
||||
$user = $USER;
|
||||
|
||||
} else {
|
||||
// throw an error here
|
||||
print_error('wrongcontextid');
|
||||
exit;
|
||||
if ( !$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $contextid . '&sesskey='. sesskey();
|
||||
} else if ($context->contextlevel == CONTEXT_USER) {
|
||||
$pagename = get_string("personalrepositories",'repository');
|
||||
//is the user looking at its own repository instances
|
||||
if ($USER->id != $context->instanceid){
|
||||
print_error('notyourinstances', 'repository');
|
||||
}
|
||||
$user = $USER;
|
||||
|
||||
} else {
|
||||
print_error('invalidcontext');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Security: we cannot perform any action if the type is not visible or if the context has been disabled
|
||||
if (!empty($new)){
|
||||
$type = repository::get_type_by_typename($new);
|
||||
} else if (!empty($edit)){
|
||||
$instance = repository::get_instance($edit);
|
||||
$type = repository::get_type_by_id($instance->options['typeid']);
|
||||
} else if (!empty($delete)){
|
||||
$instance = repository::get_instance($delete);
|
||||
$type = repository::get_type_by_id($instance->options['typeid']);
|
||||
}
|
||||
if (isset($type) && ( !$type->get_visible() || (!$type->get_contextvisibility($context->contextlevel)) ) ) {
|
||||
print_error('typenotvisible', 'repository', $baseurl);
|
||||
}
|
||||
if (!empty($new)){
|
||||
$type = repository::get_type_by_typename($new);
|
||||
} else if (!empty($edit)){
|
||||
$instance = repository::get_instance($edit);
|
||||
$type = repository::get_type_by_id($instance->options['typeid']);
|
||||
} else if (!empty($delete)){
|
||||
$instance = repository::get_instance($delete);
|
||||
$type = repository::get_type_by_id($instance->options['typeid']);
|
||||
}
|
||||
|
||||
if (isset($type) && !$type->get_visible()) {
|
||||
print_error('typenotvisible', 'repository', $baseurl);
|
||||
}
|
||||
|
||||
if (isset($type) && !$type->get_contextvisibility($context)) {
|
||||
print_error('usercontextrepositorydisabled', 'repository', $baseurl);
|
||||
}
|
||||
|
||||
/// Create navigation links
|
||||
if (!empty($course)) {
|
||||
$PAGE->navbar->add($pagename);
|
||||
$fullname = $course->fullname;
|
||||
} else {
|
||||
$fullname = fullname($user);
|
||||
$strrepos = get_string('repositories', 'repository');
|
||||
$PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id)));
|
||||
$PAGE->navbar->add($strrepos);
|
||||
}
|
||||
if (!empty($course)) {
|
||||
$PAGE->navbar->add($pagename);
|
||||
$fullname = $course->fullname;
|
||||
} else {
|
||||
$fullname = fullname($user);
|
||||
$strrepos = get_string('repositories', 'repository');
|
||||
$PAGE->navbar->add($fullname, new moodle_url($CFG->wwwroot.'/user/view.php', array('id'=>$user->id)));
|
||||
$PAGE->navbar->add($strrepos);
|
||||
}
|
||||
|
||||
$title = $pagename;
|
||||
$title = $pagename;
|
||||
|
||||
/// Display page header
|
||||
$PAGE->set_title();
|
||||
$PAGE->set_heading($fullname);
|
||||
echo $OUTPUT->header();
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($fullname);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
if ( !$course = $DB->get_record('course', array('id'=>$usercourseid))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
$currenttab = 'repositories';
|
||||
include($CFG->dirroot.'/user/tabs.php');
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
if ( !$course = $DB->get_record('course', array('id'=>$usercourseid))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
$currenttab = 'repositories';
|
||||
include($CFG->dirroot.'/user/tabs.php');
|
||||
}
|
||||
|
||||
echo $OUTPUT->heading($pagename);
|
||||
echo $OUTPUT->heading($pagename);
|
||||
|
||||
$return = true;
|
||||
$return = true;
|
||||
|
||||
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->options['typeid']);
|
||||
$classname = 'repository_' . $instancetype->get_typename();
|
||||
$configs = $instance->get_instance_option_names();
|
||||
$plugin = $instancetype->get_typename();
|
||||
$typeid = $instance->options['typeid'];
|
||||
} else {
|
||||
$plugin = $new;
|
||||
$typeid = $new;
|
||||
$instance = null;
|
||||
}
|
||||
|
||||
/// Create edit form for this instance
|
||||
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance, 'contextid' => $contextid));
|
||||
|
||||
/// Process the form data if any, or display
|
||||
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;
|
||||
foreach($configs as $config) {
|
||||
$settings[$config] = $fromform->$config;
|
||||
}
|
||||
$success = $instance->set_option($settings);
|
||||
} else {
|
||||
$success = repository::static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform);
|
||||
$data = data_submitted();
|
||||
}
|
||||
if ($success) {
|
||||
$savedstr = get_string('configsaved', 'repository');
|
||||
//admin_externalpage_print_header();
|
||||
echo $OUTPUT->heading($savedstr);
|
||||
redirect($baseurl, $savedstr, 3);
|
||||
} else {
|
||||
print_error('instancenotsaved', 'repository', $baseurl);
|
||||
}
|
||||
exit;
|
||||
} else { // Display the form
|
||||
// admin_externalpage_print_header();
|
||||
echo $OUTPUT->heading(get_string('configplugin', 'repository_'.$plugin));
|
||||
$OUTPUT->box_start();
|
||||
$mform->display();
|
||||
$OUTPUT->box_end();
|
||||
$return = false;
|
||||
}
|
||||
} else if (!empty($delete)) {
|
||||
// admin_externalpage_print_header();
|
||||
$instance = repository::get_instance($delete);
|
||||
//if you try to delete an instance set as readonly, display an error message
|
||||
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');
|
||||
}
|
||||
if ($sure) {
|
||||
if (!confirm_sesskey()) {
|
||||
print_error('confirmsesskeybad', '', $baseurl);
|
||||
}
|
||||
if ($instance->delete()) {
|
||||
$deletedstr = get_string('instancedeleted', 'repository');
|
||||
echo $OUTPUT->heading($deletedstr);
|
||||
redirect($baseurl, $deletedstr, 3);
|
||||
} else {
|
||||
print_error('instancenotdeleted', 'repository', $baseurl);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
$formcontinue = html_form::make_button($baseurl, array('delete' => $delete, 'sure' => 'yes'), get_string('yes'));
|
||||
$formcancel = html_form::make_button($baseurl, array(), get_string('no'));
|
||||
echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), $formcontinue, $formcancel);
|
||||
$return = false;
|
||||
$instancetype = repository::get_type_by_id($instance->options['typeid']);
|
||||
$classname = 'repository_' . $instancetype->get_typename();
|
||||
$configs = $instance->get_instance_option_names();
|
||||
$plugin = $instancetype->get_typename();
|
||||
$typeid = $instance->options['typeid'];
|
||||
} else {
|
||||
repository::display_instances_list($context);
|
||||
$plugin = $new;
|
||||
$typeid = $new;
|
||||
$instance = null;
|
||||
}
|
||||
|
||||
/// Create edit form for this instance
|
||||
$mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance, 'contextid' => $contextid));
|
||||
|
||||
/// Process the form data if any, or display
|
||||
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;
|
||||
foreach($configs as $config) {
|
||||
$settings[$config] = $fromform->$config;
|
||||
}
|
||||
$success = $instance->set_option($settings);
|
||||
} else {
|
||||
$success = repository::static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform);
|
||||
$data = data_submitted();
|
||||
}
|
||||
if ($success) {
|
||||
$savedstr = get_string('configsaved', 'repository');
|
||||
//admin_externalpage_print_header();
|
||||
echo $OUTPUT->heading($savedstr);
|
||||
redirect($baseurl, $savedstr, 3);
|
||||
} else {
|
||||
print_error('instancenotsaved', 'repository', $baseurl);
|
||||
}
|
||||
exit;
|
||||
} else { // Display the form
|
||||
// admin_externalpage_print_header();
|
||||
echo $OUTPUT->heading(get_string('configplugin', 'repository_'.$plugin));
|
||||
$OUTPUT->box_start();
|
||||
$mform->display();
|
||||
$OUTPUT->box_end();
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if (!empty($return)) {
|
||||
redirect($baseurl);
|
||||
} else if (!empty($delete)) {
|
||||
// admin_externalpage_print_header();
|
||||
$instance = repository::get_instance($delete);
|
||||
//if you try to delete an instance set as readonly, display an error message
|
||||
if ($instance->readonly) {
|
||||
throw new repository_exception('readonlyinstance', 'repository');
|
||||
}
|
||||
if ($sure) {
|
||||
if (!confirm_sesskey()) {
|
||||
print_error('confirmsesskeybad', '', $baseurl);
|
||||
}
|
||||
if ($instance->delete()) {
|
||||
$deletedstr = get_string('instancedeleted', 'repository');
|
||||
echo $OUTPUT->heading($deletedstr);
|
||||
redirect($baseurl, $deletedstr, 3);
|
||||
} else {
|
||||
print_error('instancenotdeleted', 'repository', $baseurl);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
$formcontinue = html_form::make_button($baseurl, array('delete' => $delete, 'sure' => 'yes'), get_string('yes'));
|
||||
$formcancel = html_form::make_button($baseurl, array(), get_string('no'));
|
||||
echo $OUTPUT->confirm(get_string('confirmdelete', 'repository', $instance->name), $formcontinue, $formcancel);
|
||||
$return = false;
|
||||
} else {
|
||||
repository::display_instances_list($context);
|
||||
$return = false;
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
if (!empty($return)) {
|
||||
redirect($baseurl);
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
Reference in New Issue
Block a user