~ubuntu-branches/ubuntu/maverick/mahara/maverick-updates

« back to all changes in this revision

Viewing changes to htdocs/artefact/file/upload.php

  • Committer: Bazaar Package Importer
  • Author(s): Nigel McNie
  • Date: 2008-04-29 11:15:39 UTC
  • Revision ID: james.westby@ubuntu.com-20080429111539-b28eqkagavaub2zr
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 *
 
19
 * @package    mahara
 
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
 
24
 *
 
25
 */
 
26
 
 
27
define('INTERNAL', 1);
 
28
define('IFRAME', 1);
 
29
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
 
30
safe_require('artefact', 'file');
 
31
global $USER;
 
32
 
 
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);
 
41
 
 
42
$data = new StdClass;
 
43
if ($parentfolder) {
 
44
    $data->parent = (int) $parentfolder;
 
45
}
 
46
$data->title = $title;
 
47
$data->description = $description;
 
48
$data->tags = $tags;
 
49
$data->owner = $USER->get('id');
 
50
$data->adminfiles = (int) $adminfiles;
 
51
$data->container = 0;
 
52
$data->locked = 0;
 
53
 
 
54
$result = new StdClass;
 
55
$result->uploadnumber = $uploadnumber;
 
56
 
 
57
if ($oldid = ArtefactTypeFileBase::file_exists($title, $data->owner, $parentfolder, $adminfiles)) {
 
58
    if ($collideaction == 'replace') {
 
59
        $obj = artefact_instance_from_id($oldid);
 
60
        $obj->delete();
 
61
    }
 
62
    else {
 
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);
 
67
    }
 
68
}
 
69
if (!isset($result->error)) {
 
70
    $errmsg = ArtefactTypeFile::save_uploaded_file('userfile', $data);
 
71
    if (!$errmsg) {
 
72
        $result->error = false;
 
73
        if ($parentfoldername) {
 
74
            $result->message = get_string('uploadoffiletofoldercomplete', 'artefact.file', 
 
75
                                          $title, $parentfoldername);
 
76
        }
 
77
        else {
 
78
            $result->message = get_string('uploadoffilecomplete', 'artefact.file', $title);
 
79
        }
 
80
    }
 
81
    else {
 
82
        $result->error = 'local';
 
83
        if ($parentfoldername) {
 
84
            $result->message = get_string('uploadoffiletofolderfailed', 'artefact.file', 
 
85
                                          $title, $parentfoldername);
 
86
        }
 
87
        else {
 
88
            $result->message = get_string('uploadoffilefailed', 'artefact.file',  $title);
 
89
        }
 
90
        $result->message .= ': ' . $errmsg;
 
91
    }
 
92
}
 
93
 
 
94
$result->quota = $USER->get('quota');
 
95
$result->quotaused = $USER->get('quotaused');
 
96
 
 
97
$r = json_encode($result);
 
98
$frame = <<< EOF
 
99
<html><head><script>
 
100
<!--
 
101
function senduploadresult() {
 
102
  var x = {$r};
 
103
  parent.uploader.getresult(x);
 
104
}
 
105
// -->
 
106
</script></head>
 
107
<body onload="senduploadresult()"></body>
 
108
</html>
 
109
EOF;
 
110
 
 
111
header('Content-type: text/html');
 
112
echo $frame;
 
113
 
 
114
?>