3
* Mahara: Electronic portfolio, weblog, resume builder and social networking
4
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
* @subpackage artefact-file
21
* @author Catalyst IT Ltd
22
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
23
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
27
define('INTERNAL', 1);
29
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
30
safe_require('artefact', 'file');
33
$parentfolder = param_variable('parentfolder', null); // id of parent artefact
34
$parentfoldername = param_variable('parentfoldername', ''); // path to parent folder
35
$title = param_variable('title');
36
$description = param_variable('description', null);
37
$tags = param_variable('tags', null);
38
$uploadnumber = param_integer('uploadnumber'); // id of target iframe
39
$collideaction = param_variable('collideaction', 'fail');
40
$adminfiles = param_boolean('adminfiles', false);
44
$data->parent = (int) $parentfolder;
46
$data->title = $title;
47
$data->description = $description;
49
$data->owner = $USER->get('id');
50
$data->adminfiles = (int) $adminfiles;
54
$result = new StdClass;
55
$result->uploadnumber = $uploadnumber;
57
if ($oldid = ArtefactTypeFileBase::file_exists($title, $data->owner, $parentfolder, $adminfiles)) {
58
if ($collideaction == 'replace') {
59
$obj = artefact_instance_from_id($oldid);
63
// Hopefully this will happen rarely as filename clashes are
64
// detected in the javascript.
65
$result->error = 'fileexists';
66
$result->message = get_string('fileexistsonserver', 'artefact.file', $title);
69
if (!isset($result->error)) {
70
$errmsg = ArtefactTypeFile::save_uploaded_file('userfile', $data);
72
$result->error = false;
73
if ($parentfoldername) {
74
$result->message = get_string('uploadoffiletofoldercomplete', 'artefact.file',
75
$title, $parentfoldername);
78
$result->message = get_string('uploadoffilecomplete', 'artefact.file', $title);
82
$result->error = 'local';
83
if ($parentfoldername) {
84
$result->message = get_string('uploadoffiletofolderfailed', 'artefact.file',
85
$title, $parentfoldername);
88
$result->message = get_string('uploadoffilefailed', 'artefact.file', $title);
90
$result->message .= ': ' . $errmsg;
94
$result->quota = $USER->get('quota');
95
$result->quotaused = $USER->get('quotaused');
97
$r = json_encode($result);
101
function senduploadresult() {
103
parent.uploader.getresult(x);
107
<body onload="senduploadresult()"></body>
111
header('Content-type: text/html');