$CFG->pagepath = 'admin/managerepository/' . $plugin;
// display the edit form for this instance
$mform = new repository_admin_form('', array('plugin' => $plugin, 'instance' => $repositorytype));
+ $fromform = $mform->get_data();
// end setup, begin output
if ($mform->is_cancelled()){
redirect($baseurl);
exit;
- } else if ($fromform = $mform->get_data() || (!empty($new) && !repository_static_function($new,"has_admin_config"))){
+ } else if (!empty($fromform) || (!empty($new) && !repository_static_function($new,"has_admin_config"))){
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
if ($edit){
if (repository_static_function($edit,"has_instance_config")
|| repository_static_function($edit,"has_multiple_instances")){
- repository_display_instances_list(get_context_instance(CONTEXT_SYSTEM), true, $edit);
+ repository_display_instances_list(get_context_instance(CONTEXT_SYSTEM), $edit);
}
}
$move = optional_param('move', '', PARAM_ALPHA);
$type = optional_param('type', '', PARAM_ALPHA);
+$context = get_context_instance(CONTEXT_SYSTEM);
+
$display = true; // fall through to normal display
$pagename = 'repositorycontroller';
}
// display the edit form for this instance
- $mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance));
+ $mform = new repository_instance_form('', array('plugin' => $plugin, 'typeid' => $typeid,'instance' => $instance, 'contextid' => $context->id));
// end setup, begin output
if ($mform->is_cancelled()){
}
}
- /// Repository Account
- if ($course->id !== SITEID) {
- $this->content->items[]='<a href="'.$CFG->wwwroot.'/repository/manage.php?id='.$USER->id.'&course='.$course->id.'&context=course">'.get_string('repositories').'</a>';
+ /// Repository Instances
+ if ($course->id !== SITEID && has_capability('moodle/course:update', $context)) {
+ $this->content->items[]='<a href="'.$CFG->wwwroot.'/repository/manage_instances.php?contextid='.$context->id.'">'.get_string('repositories').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/repository.png" alt=""/>';
}
$string['preview'] = 'Preview';
$string['removed'] = 'Repository removed';
$string['repository'] = 'Repository';
+$string['repositorycourse'] = 'Course repositories';
$string['repositories'] = 'Repositories';
$string['save'] = 'Save';
$string['saveas'] = 'Save as';
$string['sync'] = 'Sync';
$string['title'] = 'Repository file picker';
$string['thumbview'] = 'View as icons';
+$string['typenotvisible'] = 'Type not visible';
$string['updown'] = 'Display order';
$string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...';
if ( repository_static_function($i->get_typename(), 'has_admin_config')
|| repository_static_function($i->get_typename(), 'has_instance_config')
|| repository_static_function($i->get_typename(), 'has_multiple_instances')) {
- $settings .= '<a href="' . $this->baseurl . '&edit=' . $i->get_typename() . '">'. $settingsstr .'</a>' . "\n";
+ $settings .= '<a href="' . $this->baseurl . '&edit=' . $i->get_typename() . '">'
+ . $settingsstr .'</a>' . "\n";
}
- $delete = '<a href="' . $this->baseurl . '&delete=' . $i->get_typename() . '">' . $deletestr . '</a>' . "\n";
+ $delete = '<a href="' . $this->baseurl . '&delete=' . $i->get_typename() . '">'
+ . $deletestr . '</a>' . "\n";
- $hiddenshow = ' <a href="' . $this->baseurl . '&hide=' . $i->get_typename() . '"><img src="' . $CFG->pixpath . '/i/' . ($i->get_visible() ? 'hide' : 'show') . '.gif" alt="' . get_string($i->get_visible() ? 'hide' : 'show') . '" /></a>' . "\n";
+ $hiddenshow = ' <a href="' . $this->baseurl . '&hide=' . $i->get_typename() . '">'
+ .'<img src="' . $CFG->pixpath . '/i/' . ($i->get_visible() ? 'hide' : 'show') . '.gif"'
+ .' alt="' . get_string($i->get_visible() ? 'hide' : 'show') . '" />'
+ .'</a>' . "\n";
// display up/down link
$updown = '';
return true;
}
+ public static function has_multiple_instances() {
+ return true;
+ }
+
+ public static function has_instance_config() {
+ return false;
+ }
+
public function admin_config_form(&$mform) {
$api_key = get_config('flickr', 'api_key');
if (empty($api_key)) {
* @param string $type a type name to retrieve
* @return array repository instances
*/
-function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null){
+function repository_get_instances($context=null, $userid = null, $onlyvisible = true, $type=null, $nositeinstances=true){
global $DB, $CFG, $USER;
$params = array();
$sql = 'SELECT i.*, r.type AS repositorytype, r.sortorder, r.visible FROM {repository} r, {repository_instances} i WHERE ';
$sql .= ' AND (i.contextid = ?)';
$params[] = SYSCONTEXTID;
} else {
- $sql .= ' AND (i.contextid = ? or i.contextid = ?)';
- $params[] = SYSCONTEXTID;
+ if ($nositeinstances) {
+ $sql .= ' AND i.contextid = ?';
+ } else {
+ $sql .= ' AND (i.contextid = ? or i.contextid = ?)';
+ $params[] = SYSCONTEXTID;
+ }
$params[] = $context->id;
}
}
// type of plugin, string
$this->plugin = $this->_customdata['plugin'];
$this->typeid = $this->_customdata['typeid'];
+ $this->contextid = $this->_customdata['contextid'];
$this->instance = (isset($this->_customdata['instance'])
&& is_subclass_of($this->_customdata['instance'], 'repository'))
? $this->_customdata['instance'] : null;
$mform->addElement('hidden', 'new', $this->plugin);
$mform->addElement('hidden', 'plugin', $this->plugin);
$mform->addElement('hidden', 'typeid', $this->typeid);
+ $mform->addElement('hidden', 'contextid', $this->contextid);
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
$mform->addRule('name', $strrequired, 'required', null, 'client');
}
// and set the data if we have some.
- //var_dump($this);
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
}
$this->set_data($data);
}
-
$this->add_action_buttons(true, get_string('save','repository'));
}
* @global object $CFG
* @global object $USER
* @param object $context the context for which we display the instance
- * @param boolean $admin if true, so the form is been called by an administration
- * page, only one type would be displayed
* @param string $typename if set, we display only one type of instance
*/
-function repository_display_instances_list($context, $admin = false, $typename = null){
+function repository_display_instances_list($context, $typename = null){
global $CFG, $USER;
- if ($admin) {
- $baseurl = $CFG->wwwroot . '/admin/repositoryinstance.php?sesskey=' . sesskey();
- $type = repository_get_type_by_typename($typename);
-
- }
- $output = print_simple_box_start(true);
- if ($admin) {
+ $output = print_box_start('generalbox','',true);
+ //if the context is SYSTEM, so we call it from administration page
+ $admin = ($context->id == SYSCONTEXTID) ? true : false;
+ if($admin) {
+ $baseurl = $CFG->wwwroot . '/admin/repositoryinstance.php?sesskey=' . sesskey();
$output .= "<div ><h2 style='text-align: center'>" . get_string('siteinstances', 'repository') . " ";
- }
- $output .= "</h2></div>";
+ $output .= "</h2></div>";
+ } else {
+ $baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&sesskey=' . sesskey();
+ }
+
$namestr = get_string('name');
$pluginstr = get_string('plugin', 'repository');
$settingsstr = get_string('settings');
$updown = get_string('updown', 'repository');
$plugins = get_list_of_plugins('repository');
//retrieve list of instances. In administration context we want to display all
- //instances even if the type is not visible. In course/user context we
- //want to display only visible instances. The repository_get_instances()
- //third parameter displays only visible type.
- $instances = repository_get_instances($context,null,!$admin,$typename);
+ //instances of a type, even if this type is not visible. In course/user context we
+ //want to display only visible instances, but for every type types. The repository_get_instances()
+ //third parameter displays only visible type. The fifth parameter is a trick that return
+ //instances of the $context + systemcontext.
+ $instances = repository_get_instances($context,null,!$admin,$typename, !$admin);
$instancesnumber = count($instances);
$alreadyplugins = array();
$table = new StdClass;
$settings .= '<a href="' . $baseurl . '&type='.$typename.'&edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
$delete = '<a href="' . $baseurl . '&type='.$typename.'&delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
+ $type = repository_get_type_by_id($i->typeid);
$table->data[] = array($i->name, $type->get_readablename(), $delete, $settings);
-
//display a grey row if the type is defined as not visible
if (isset($type) && !$type->get_visible()){
$table->rowclass[] = 'dimmed_text';
$instancehtml .= get_string('createrepository', 'repository');
$instancehtml .= '</h3><ul>';
foreach ($plugins as $p) {
- if (!in_array($p, $alreadyplugins)) {
- if (repository_static_function($p->get_typename(), 'has_multiple_instances')){
- $instancehtml .= '<li><a href="'.$baseurl.'&new='.$p.'">'.get_string('create', 'repository')
- .' "'.get_string('repositoryname', 'repository_'.$p).'" '
- .get_string('instance', 'repository').'</a></li>';
- $addable++;
- }
- }
+ $type = repository_get_type_by_typename($p);
+ if ($type->get_visible()) {
+ if (repository_static_function($p, 'has_multiple_instances')){
+ $instancehtml .= '<li><a href="'.$baseurl.'&new='.$p.'">'.get_string('create', 'repository')
+ .' "'.get_string('repositoryname', 'repository_'.$p).'" '
+ .get_string('instance', 'repository').'</a></li>';
+ $addable++;
+ }
+ }
}
$instancehtml .= '</ul>';
}
}
}
-
-
if ($addable) {
$instancehtml .= '</div>';
$output .= $instancehtml;
}
- $output .= print_simple_box_end(true);
+ $output .= print_box_end(true);
//print the list + creation links
print($output);
-
}
--- /dev/null
+<?php
+// $Id$
+require_once(dirname(dirname(__FILE__)) . '/config.php');
+require_once($CFG->dirroot . '/repository/lib.php');
+//require_once($CFG->libdir . '/adminlib.php');
+
+// id of repository
+$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);
+
+$display = true; // fall through to normal display
+
+if ($edit){
+ $pagename = 'repositoryinstanceedit';
+}else if ($delete) {
+ $pagename = 'repositorydelete';
+} else if ($new) {
+ $pagename = 'repositoryinstancenew';
+}
+else {
+ $pagename = 'repositorylist';
+}
+
+require_login(SITEID, false);
+
+$context = get_context_instance_by_id($contextid);
+
+//security: detect if we are in a course context
+if ($context->contextlevel == CONTEXT_COURSE) {
+ $pagename = get_string("repositorycourse",'repository');
+
+ //is the user is allowed to edit this course, he's allowed to edit list of repository instances
+ require_capability('moodle/course:update', $context);
+ //retrieve course
+ //Retrieve the course object
+ if ( !$course = $DB->get_record('course', array('id'=>$context->instanceid))) {
+ print_error('invalidcourseid');
+ }
+}
+
+$baseurl = $CFG->wwwroot . '/repository/manage_instances.php?contextid=' . $contextid . '&sesskey='. sesskey();
+
+//security: we cannot perform any action if the type is not visible
+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->typeid);
+} else if (!empty($delete)){
+ $instance = repository_get_instance($delete);
+ $type = repository_get_type_by_id($instance->typeid);
+}
+if (isset($type) && !$type->get_visible()) {
+ print_error('typenotvisible', 'repository', $baseurl);
+}
+
+
+
+//Create header crumbtrail
+//$streditrepositoryaccount = get_string("editrepositoryinstance",'repository');
+$navlinks = array();
+if (!empty($course)) {
+ $navlinks[] = array('name' => $course->shortname,
+ 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
+ 'type' => 'misc');
+ $navlinks[] = array('name' => $pagename,
+ 'link' => null,
+ 'type' => 'misc');
+ $title = $pagename;
+ $fullname = $course->fullname;
+}
+$navigation = build_navigation($navlinks);
+
+//display page header
+print_header($title, $fullname, $navigation);
+print_heading($pagename);
+
+$return = true;
+
+if (!empty($edit) || !empty($new)) {
+ if (!empty($edit)) {
+ $instance = repository_get_instance($edit);
+ $instancetype = repository_get_type_by_id($instance->typeid);
+ $classname = 'repository_' . $instancetype->get_typename();
+ $configs = $instance->get_instance_option_names();
+ $plugin = $instancetype->get_typename();
+ $typeid = $instance->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));
+ // end setup, begin output
+
+ 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();
+ print_heading($savedstr);
+ redirect($baseurl, $savedstr, 3);
+ } else {
+ print_error('instancenotsaved', 'repository', $baseurl);
+ }
+ exit;
+ } else {
+ // admin_externalpage_print_header();
+ print_heading(get_string('configplugin', 'repository_'.$plugin));
+ print_simple_box_start();
+ $mform->display();
+ print_simple_box_end();
+ $return = false;
+ }
+} else if (!empty($delete)) {
+ // admin_externalpage_print_header();
+ $instance = repository_get_instance($delete);
+ if ($sure) {
+ if (!confirm_sesskey()) {
+ print_error('confirmsesskeybad', '', $baseurl);
+ }
+ if ($instance->delete()) {
+ $deletedstr = get_string('instancedeleted', 'repository');
+ print_heading($deletedstr);
+ redirect($baseurl, $deletedstr, 3);
+ } else {
+ print_error('instancenotdeleted', 'repository', $baseurl);
+ }
+ exit;
+ }
+ notice_yesno(get_string('confirmdelete', 'repository', $instance->name), $baseurl . '&delete=' . $delete . '&sure=yes', $baseurl);
+ $return = false;
+} else {
+ repository_display_instances_list($context);
+ $return = false;
+}
+
+if (!empty($return)) {
+ redirect($baseurl);
+}
+
+//display page footer
+print_footer($course);
\ No newline at end of file