"MDL-13766, repository settings page"
authordongsheng <dongsheng>
Mon, 28 Jul 2008 08:24:55 +0000 (08:24 +0000)
committerdongsheng <dongsheng>
Mon, 28 Jul 2008 08:24:55 +0000 (08:24 +0000)
lang/en_utf8/repository.php [new file with mode: 0644]
repository/ajax.php
repository/boxnet/lang/en_utf8/repository_boxnet.php
repository/boxnet/repository.class.php
repository/flickr/repository.class.php
repository/lib.php
repository/ws.php
user/repository.php [new file with mode: 0644]
user/tabs.php

diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php
new file mode 100644 (file)
index 0000000..0593262
--- /dev/null
@@ -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';
index c7608e6..b2694d3 100644 (file)
@@ -364,7 +364,7 @@ var repository_client = (function() {
         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;
index 80f1e42..15833f0 100644 (file)
@@ -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.';
index 7b967ba..e575648 100755 (executable)
@@ -12,6 +12,7 @@ require_once($CFG->dirroot.'/repository/boxnet/'.'boxlibphp5.php');
 
 class repository_boxnet extends repository{
     private $box;
+    public $type = 'boxnet';
 
     public function __construct($repositoryid, $context = SITEID, $options = array()){
         global $SESSION, $action;
@@ -55,6 +56,16 @@ class repository_boxnet extends repository{
         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();
@@ -104,16 +115,17 @@ class repository_boxnet extends repository{
         } 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']){
index 15b1ab7..c3da919 100755 (executable)
 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);
index feb6382..2844121 100644 (file)
@@ -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;
@@ -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();
@@ -212,13 +211,17 @@ abstract class repository {
      * @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;
@@ -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/';
index e48ef03..3221780 100644 (file)
@@ -32,7 +32,7 @@ if(file_exists($CFG->dirroot.'/repository/'.
     } catch (repository_exception $e){
         $err = new stdclass;
         $err->e = $e->getMessage();
-        die(json_encode($err));
+        die(json_encode($err.time()));
     }
 } else {
     $err = new stdclass;
diff --git a/user/repository.php b/user/repository.php
new file mode 100644 (file)
index 0000000..c52c0ab
--- /dev/null
@@ -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();
+
+?>
index 8c10d58..5316659 100644 (file)
             // @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