MDL-15565, fix bug of maintenance mode alert reminder
[moodle.git] / repository / ws.php
CommitLineData
0eb58cf4 1<?php
1e28c767 2set_time_limit(0);
0eb58cf4 3require_once('../config.php');
4require_once('lib.php');
5bce5972 5$CFG->repository_cache_expire = 12000;
75e7a38c 6// repository id
1e28c767 7$id = optional_param('id', PARAM_INT);
75e7a38c 8// action of client
1e28c767 9$action = optional_param('action', '', PARAM_RAW);
75e7a38c 10// Search text
1e28c767 11$search = optional_param('s', '', PARAM_RAW);
12// files to be downloaded
bb2c046d 13$file = optional_param('file', '', PARAM_RAW);
14$title = optional_param('title', '', PARAM_RAW);
15$p = optional_param('p', '', PARAM_RAW);
5bce5972 16
0eb58cf4 17if(!$repository = $DB->get_record('repository', array('id'=>$id))) {
18 echo json_encode('wrong');
19 die;
20}
21
22if(is_file($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php')) {
23 require_once($CFG->dirroot.'/repository/'.$repository->repositorytype.'/repository.class.php');
24 $classname = 'repository_' . $repository->repositorytype;
25 $repo = new $classname($id, SITEID, array('ajax'=>true));
26} else {
27 print_error('invalidplugin', 'repository');
28 echo json_encode('invalidplugin');
29 die;
30}
31
32if($action == 'list') {
5bce5972 33 if(!empty($p)) {
34 echo json_encode($repo->get_listing($p));
35 } else if(!empty($search)) {
36 echo json_encode($repo->get_listing('', $search));
37 } else {
38 echo json_encode($repo->get_listing());
39 }
75e7a38c 40
1e28c767 41} elseif($action == 'download') {
bb2c046d 42 $ret = $repo->get_file($file, $title);
43 // TODO
44 // Need to communicate with FILE API
45 // Copy the tmp file to final location
1e28c767 46 echo json_encode($ret);
0eb58cf4 47} else {
48 echo json_encode($repo->print_login());
49}
50
51?>