class repository_boxnet extends repository{
- var $api_key = 'dmls97d8j3i9tn7av8y71m9eb55vrtj4';
var $box;
var $ticket;
public function __construct($repositoryid, $context = SITEID, $options = array()){
- $repositoryid = -1;
+ global $SESSION;
+ $op = repository_get_option($repositoryid, 1);
+ $options['api_key'] = $op['api_key'];
+ $options['auth_token'] = optional_param('auth_token', '', PARAM_RAW);
+ if(!empty($options['auth_token'])) {
+ $SESSION->box_token = $options['auth_token'];
+ } else {
+ $options['auth_token'] = $SESSION->box_token;
+ }
+ $options['api_key'] = 'dmls97d8j3i9tn7av8y71m9eb55vrtj4';
parent::__construct($repositoryid, $context, $options);
if(!empty($options['api_key'])){
$this->api_key = $options['api_key'];
$ret[] = array('name'=>$v, 'size'=>0, 'date'=>'',
'url'=>'http://box.net/api/1.0/download/'.$this->options['auth_token'].'/'.$fileids[$n]);
}
+ $this->listing = $ret;
return $ret;
} else {
return null;
}
public function print_login(){
- if($this->box){
+ if(!empty($this->box) && !empty($this->options['auth_token'])) {
+ echo '<a href="picker.php?id='.$this->repositoryid.'&action=list">View File list</a>';
+ return true;
+ } else if(!empty($this->box)){
// get a ticket from box.net
$ticket_return = $this->box->getTicket();
if($this->box->isError()) {
if($this->ticket && ($this->options['auth_token'] == '')){
$this->box->getAuthToken($this->ticket);
return false;
- } else {
- echo 'Logged';
- return true;
}
} else {
return false;
<?php
require_once('../config.php');
require_once('lib.php');
-// Obtain parameters
$id = required_param('id', PARAM_INT);
-$options = repository_get_option($id, 1);
-if(!empty($options['required'])) {
- foreach($options['required'] as $param){
- $options[$param] = optional_param($param, 0, PARAM_RAW);
- }
-}
-$courseid = optional_param('course', 0, PARAM_INT);
-$contextid = SITEID;
-
-/*
-if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
- print_error('invalidcourseid');
-}
-*/
+$action = optional_param('action', 'check', PARAM_RAW);
if(!$repository = $DB->get_record('repository', array('id'=>$id))) {
print_error('invalidrepostoryid');
}
-require_once($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php');
-$classname = 'repository_'.$repository->repositorytype;
-$repo = new $classname($id, SITEID, $options);
+
+if(is_file($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php')) {
+ require_once($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php');
+ $classname = 'repository_' . $repository->repositorytype;
+ $repo = new $classname($id, SITEID);
+} else {
+ print_error('invalidplugin', 'repository');
+}
+
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
-<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
-<title>File Picker</title>
-<link href="style.css" rel="stylesheet" type="text/css"/>
+ <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
+ <title>File Picker</title>
+ <link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<table border="0" cellspacing="10" cellpadding="10">
</table>
<div>
<?php
- $repo->print_login();
+ if(!empty($action)) {
+ $repo->print_listing();
+ } else {
+ $repo->print_login();
+ }
?>
</div>
<!--