Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
"MDL-13766, repository settings page"
  • Loading branch information
dongsheng committed Jul 28, 2008
1 parent 3efe78d commit 19add4c
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 17 deletions.
6 changes: 6 additions & 0 deletions lang/en_utf8/repository.php
@@ -0,0 +1,6 @@
<?php //$Id$
$string['repository'] = 'Repository';
$string['repositories'] = 'Repositories';
$string['manageuserrepository'] = 'Manage individual repository';
$string['plugin'] = 'Repository Plug-ins';
$string['settings'] = 'Settings';
2 changes: 1 addition & 1 deletion repository/ajax.php
Expand Up @@ -364,7 +364,7 @@ function _client(){
try {
var ret = YAHOO.lang.JSON.parse(o.responseText);
} catch(e) {
alert('Invalid JSON String\n'+o.responseText);
alert('Callback: Invalid JSON String\n'+o.responseText);
}
if(ret.e){
panel.get('element').innerHTML = ret.e;
Expand Down
4 changes: 4 additions & 0 deletions repository/boxnet/lang/en_utf8/repository_boxnet.php
@@ -1,3 +1,7 @@
<?php
$string['repositoryname'] = 'Box.net';
$string['repositorydesc'] = 'Repository for box.net';
$string['configplugin'] = 'Box.net configuration';
$string['username'] = 'Username for Box.net';
$string['password'] = 'Password';
$string['saved'] = 'Box.net data saved.';
16 changes: 14 additions & 2 deletions repository/boxnet/repository.class.php
Expand Up @@ -12,6 +12,7 @@

class repository_boxnet extends repository{
private $box;
public $type = 'boxnet';

public function __construct($repositoryid, $context = SITEID, $options = array()){
global $SESSION, $action;
Expand Down Expand Up @@ -55,6 +56,16 @@ public function __construct($repositoryid, $context = SITEID, $options = array()
parent::__construct($repositoryid, $context, $options);
}

public function get_login(){
global $DB;
$repository = new stdclass;
$repository->id = $this->repositoryid;
if ($entry = $DB->get_record('repository', $repository)) {
$ret->username = $entry->username;
$ret->password = $entry->password;
}
return $ret;
}
public function get_listing($path = '/', $search = ''){
global $CFG;
$list = array();
Expand Down Expand Up @@ -104,16 +115,17 @@ public function print_login(){
} else {
$t = $this->box->getTicket();
if(empty($this->options['auth_token'])) {
$ret = $this->get_login();
$str = '';
$str .= '<form id="moodle-repo-login">';
$str .= '<input type="hidden" name="ticket" value="'.
$t['ticket'].'" />';
$str .= '<input type="hidden" name="id" value="'.$this->repositoryid.'" />';
$str .= '<label for="box_username">Username: <label><br/>';
$str .= '<input type="text" id="box_username" name="username" />';
$str .= '<input type="text" id="box_username" name="username" value="'.$ret->username.'" />';
$str .= '<br/>';
$str .= '<label for="box_password">Password: <label><br/>';
$str .= '<input type="password" id="box_password" name="password" /><br/>';
$str .= '<input type="password" value="'.$ret->password.'" id="box_password" name="password" /><br/>';
$str .= '<input type="button" onclick="repository_client.login()" value="Go" />';
$str .= '</form>';
if($this->options['ajax']){
Expand Down
6 changes: 4 additions & 2 deletions repository/flickr/repository.class.php
Expand Up @@ -11,8 +11,10 @@
require_once($CFG->dirroot.'/repository/flickr/'.'phpFlickr.php');

class repository_flickr extends repository{
var $flickr;
var $photos;
private $flickr;
public $photos;
public $type = 'flickr';

public function __construct($repositoryid, $context = SITEID, $options = array()){
global $SESSION, $action, $CFG;
$options['page'] = optional_param('p', 1, PARAM_INT);
Expand Down
28 changes: 21 additions & 7 deletions repository/lib.php
Expand Up @@ -50,8 +50,8 @@
* @package repository
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once('../config.php');
require_once('../lib/filelib.php');
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->libdir.'/filelib.php');

abstract class repository {
protected $options;
Expand All @@ -70,7 +70,6 @@ abstract class repository {
* @return array the list of files, including meta infomation
*/
public function __construct($repositoryid, $context = SITEID, $options = array()){
$this->name = 'repository_base';
$this->context = $context;
$this->repositoryid = $repositoryid;
$this->options = array();
Expand Down Expand Up @@ -212,13 +211,17 @@ abstract public function print_search();
* @param string $userid The id of specific user
* @return array the list of files, including meta infomation
*/
public function store_login($username = '', $password = '', $userid = -1, $contextid = SITEID) {
public function store_login($username = '', $password = '', $userid = 1, $contextid = SITEID) {
global $DB;

$repository = new stdclass;
$repository->userid = $userid;
$repository->repositorytype = $this->name;
$repository->contextid = $contextid;
if (!empty($this->repositoryid)) {
$repository->id = $this->repositoryid;
} else {
$repository->userid = $userid;
$repository->repositorytype = $this->type;
$repository->contextid = $contextid;
}
if ($entry = $DB->get_record('repository', $repository)) {
$repository->id = $entry->id;
$repository->username = $username;
Expand Down Expand Up @@ -299,6 +302,17 @@ function repository_instances(){
}
return $repos;
}
function repository_instance($id){
global $DB, $CFG;

if (!$instance = $DB->get_record('repository', array('id' => $id))) {
return false;
}
require_once($CFG->dirroot . '/repository/'. $instance->repositorytype
. '/repository.class.php');
$classname = 'repository_' . $instance->repositorytype;
return new $classname($instance->id, $instance->contextid);
}
function repository_get_plugins(){
global $CFG;
$repo = $CFG->dirroot.'/repository/';
Expand Down
2 changes: 1 addition & 1 deletion repository/ws.php
Expand Up @@ -32,7 +32,7 @@
} catch (repository_exception $e){
$err = new stdclass;
$err->e = $e->getMessage();
die(json_encode($err));
die(json_encode($err.time()));
}
} else {
$err = new stdclass;
Expand Down
57 changes: 57 additions & 0 deletions user/repository.php
@@ -0,0 +1,57 @@
<?php //$Id$

require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->dirroot . '/repository/lib.php');

$config = optional_param('config', 0, PARAM_INT);

$course = optional_param('course', SITEID, PARAM_INT);

if (! $course = $DB->get_record("course", array("id"=>$course))) {
print_error('invalidcourseid');
}

$user = $USER;
$baseurl = $CFG->wwwroot . '/user/repository.php';
$namestr = get_string('name');
$fullname = fullname($user);
$strrepos = get_string('repositories', 'repository');
$configstr = get_string('manageuserrepository', 'repository');
$pluginstr = get_string('plugin', 'repository');

require_login($course, false);

$navlinks[] = array('name' => $fullname, 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id, 'type' => 'misc');
$navlinks[] = array('name' => $strrepos, 'link' => null, 'type' => 'misc');

$navigation = build_navigation($navlinks);

print_header("$course->fullname: $fullname: $strrepos", $course->fullname,
$navigation, "", "", true, "&nbsp;", navmenu($course));

$currenttab = 'repositories';
include('tabs.php');

print_heading($configstr);
print_simple_box_start();

if (!$instances = repository_instances(true, false)) {
print_error('noinstances', 'repository', $CFG->wwwroot . '/user/view.php');
}

$table = new StdClass;
$table->head = array($namestr, $pluginstr, '');
$table->data = array();

foreach ($instances as $i) {
$path = '/repository/'.$i->repositorytype.'/settings.php';
$settings = file_exists($CFG->dirroot.$path);
$table->data[] = array($i->repositoryname, $i->repositorytype,
$settings ? '<a href="'.$CFG->wwwroot.$path.'">'
.get_string('settings', 'repository').'</a>' : '');
}

print_table($table);
print_footer();

?>
16 changes: 12 additions & 4 deletions user/tabs.php
Expand Up @@ -247,13 +247,21 @@
// @todo penny permissions check?
$toprow[] = new tabobject('portfolios', $CFG->wwwroot .'/user/portfolio.php', get_string('portfolios', 'portfolio'));
}

/// Messaging tab
if (has_capability('moodle/user:editownmessageprofile', $systemcontext)) {
$toprow[] = new tabobject('editmessage', $CFG->wwwroot.'/message/edit.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmymessage', 'message'));
}

// Repository Tab
if ($user->id == $USER->id) {
require_once($CFG->dirroot . '/repository/lib.php');
if (repository_instances()) {
$toprow[] = new tabobject('repositories', $CFG->wwwroot .'/user/repository.php', get_string('repositories', 'repository'));
}
}

/// Messaging tab
if (has_capability('moodle/user:editownmessageprofile', $systemcontext)) {
$toprow[] = new tabobject('editmessage', $CFG->wwwroot.'/message/edit.php?id='.$user->id.'&amp;course='.$course->id, get_string('editmymessage', 'message'));
}


/// Add second row to display if there is one

Expand Down

0 comments on commit 19add4c

Please sign in to comment.