-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.php
70 lines (59 loc) · 2.05 KB
/
file.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once '../../config.php';
require_once 'lib.php';
global $DB, $OUTPUT, $PAGE, $USER;
// Get required parameters
$courseid = required_param('courseid', PARAM_INT);
$blockid = required_param('blockid', PARAM_INT);
// Next look for optional variables.
$studentid = optional_param('studentid', $USER->id, PARAM_INT);
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourse', 'block_analytics', $courseid);
}
require_login($course);
$PAGE->set_url('/blocks/analytics/about.php', array('id' => $courseid));
$PAGE->set_pagelayout('standard');
$PAGE->set_heading('Files');
$PAGE->set_title('Files');
$settingsnode = $PAGE->settingsnav->add('Files');
$editurl = new moodle_url('/blocks/analytics/file.php', array('courseid' => $courseid, 'blockid' => $blockid));
$editnode = $settingsnode->add('Files', $editurl);
$editnode->make_active();
$backurl = new moodle_url('/course/view.php', array('id' => $courseid));
// Check permission to edit
$permission = ($studentid == $USER->id);
require_once 'files/viewer.php';
if ($permission) {
// Have permission to edit
require_once 'files/file_form.php';
$err = '';
$mform = new file_form($editurl);
if ( $mform->is_cancelled() ) {
// NOP()
redirect($editurl);
} else if ( $data = $mform->get_data() ) {
$filename = $mform->get_new_filename('userfile');
$fullpath = __DIR__ . '/files/securedassets/' . $data->userid . '/' . $filename;
if (!file_exists($fullpath)) {
$state = $mform->save_file('userfile', $fullpath);
if ($state) {
$data->file = $fullpath;
$DB->insert_record('block_analytics_files', $data);
redirect($editurl);
} else {
$err = '<pre>Something is happened, cannot save file ' . $filename . ' now!</pre>';
}
} else {
$err = '<pre>File ' . $filename . ' is already exist!</pre>';
}
}
echo $OUTPUT->header();
echo $err;
echo file_viewer($studentid, true, $courseid, $blockid);
$mform->set_data(['userid' => $studentid]);
$mform->display();
} else {
// View only
echo file_viewer($studentid);
}
echo $OUTPUT->footer();