Commit fdf71aa0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Remove scripts no longer required in files area

parent e2b3d4c4
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
json_headers();
$parentfolder = param_variable('parentfolder', null); // id of parent artefact
$title = param_variable('name');
$description = param_variable('description', null);
$tags = param_variable('tags', null);
$collideaction = param_variable('collideaction', 'fail');
$institution = param_alpha('institution', null);
$group = param_integer('group', null);
$data = new StdClass;
if ($parentfolder) {
$data->parent = (int) $parentfolder;
}
$data->title = $title;
$data->description = $description;
$data->tags = $tags;
$data->owner = null;
if ($institution) {
$data->institution = $institution;
} else if ($group) {
require_once(get_config('docroot') . 'artefact/lib.php');
require_once(get_config('libroot') . 'group.php');
if ($parentfolder && !$USER->can_edit_artefact(artefact_instance_from_id($parentfolder))) {
json_reply('local', get_string('cannoteditfolder', 'artefact.file'));
} else if (!$parentfolder) {
$role = group_user_access($group);
if (!$role) {
json_reply('local', get_string('usernotingroup', 'mahara'));
}
// Use default grouptype artefact permissions to check if the
// user can create a folder in the group's root directory
$permissions = group_get_default_artefact_permissions($group);
if (!$permissions[$role]->edit) {
json_reply('local', get_string('cannoteditfolder', 'artefact.file'));
}
}
$data->group = $group;
$data->rolepermissions = (array) json_decode(param_variable('permissions'));
} else {
$data->owner = $USER->get('id');
}
if ($oldid = ArtefactTypeFileBase::file_exists($data->title, $data->owner, $parentfolder, $institution, $group)) {
if ($collideaction == 'replace') {
require_once(get_config('docroot') . 'artefact/lib.php');
$obj = artefact_instance_from_id($oldid);
$obj->delete();
}
else {
json_reply('local', get_string('fileexists', 'artefact.file'));
}
}
$f = new ArtefactTypeFolder(0, $data);
$f->set('dirty', true);
$f->commit();
json_reply(false, get_string('foldercreated', 'artefact.file'));
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$fileid = param_integer('id');
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($fileid);
if (!$USER->can_edit_artefact($artefact)) {
json_reply('local', get_string('nodeletepermission', 'mahara'));
}
$artefact->delete();
json_reply(false, array('message' => get_string('filethingdeleted', 'artefact.file',
get_string($artefact->get('artefacttype'),
'artefact.file')),
'quotaused' => $USER->get('quotaused'),
'quota' => $USER->get('quota')));
?>
This diff is collapsed.
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$artefactid = param_integer('artefact'); // Artefact being moved
$newparentid = param_integer('newparent'); // Folder to move it to
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($artefactid);
if (!$USER->can_edit_artefact($artefact)) {
json_reply(true, get_string('movefailednotowner', 'artefact.file'));
}
if (!in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) {
json_reply(true, get_string('movefailednotfileartefact', 'artefact.file'));
}
if ($newparentid > 0) {
if ($newparentid == $artefactid) {
json_reply(true, get_string('movefaileddestinationinartefact', 'artefact.file'));
}
if ($newparentid == $artefact->get('parent')) {
json_reply(false, get_string('filealreadyindestination', 'artefact.file'));
}
$newparent = artefact_instance_from_id($newparentid);
if (!$USER->can_edit_artefact($newparent)) {
json_reply(true, get_string('movefailednotowner', 'artefact.file'));
}
$group = $artefact->get('group');
if ($group && $group !== $newparent->get('group')) {
json_reply(true, get_string('movefailednotowner', 'artefact.file'));
}
if ($newparent->get('artefacttype') != 'folder') {
json_reply(true, get_string('movefaileddestinationnotfolder', 'artefact.file'));
}
$nextparentid = $newparent->get('parent');
while (!empty($nextparentid)) {
if ($nextparentid != $artefactid) {
$ancestor = artefact_instance_from_id($nextparentid);
$nextparentid = $ancestor->get('parent');
} else {
json_reply(true, get_string('movefaileddestinationinartefact', 'artefact.file'));
}
}
} else { // $newparentid === 0
if ($artefact->get('parent') == null) {
json_reply(false, get_string('filealreadyindestination', 'artefact.file'));
}
$group = $artefact->get('group');
if ($group) {
// Use default grouptype artefact permissions to check if the
// user can move a file to the group's root directory
require_once(get_config('libroot') . 'group.php');
$permissions = group_get_default_artefact_permissions($group);
if (!$permissions[group_user_access($group)]->edit) {
json_reply(true, get_string('movefailednotowner', 'artefact.file'));
}
}
$newparentid = null;
}
if ($artefact->move($newparentid)) {
json_reply(false, array('message' => null));
}
json_reply(true, get_string('movefailed', 'artefact.file'));
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
//log_debug('myfiles.json.php');
$limit = param_integer('limit', null);
$offset = param_integer('offset', 0);
$folder = param_integer('folder', null);
$institution = param_alpha('institution', null);
$group = param_integer('group', null);
$userid = $USER->get('id');
safe_require('artefact', 'file');
$filedata = ArtefactTypeFileBase::get_my_files_data($folder, $userid, $group, $institution, false);
$result = array(
'count' => count($filedata),
'limit' => $limit,
'offset' => $offset,
'data' => $filedata,
'error' => false,
'message' => false,
);
//log_debug($result);
json_headers();
print json_encode($result);
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
json_headers();
$parentfolder = param_variable('parentfolder', null); // id of parent artefact
$id = param_integer('id');
$name = param_variable('name');
$description = param_variable('description');
$tags = param_variable('tags');
$collideaction = param_variable('collideaction', 'fail');
$artefact = artefact_instance_from_id($id);
$group = $artefact->get('group');
if ($group && !$USER->can_edit_artefact($artefact)) {
json_reply('local', get_string('noeditpermission', 'mahara'));
}
if ($existingid = ArtefactTypeFileBase::file_exists($name, $artefact->get('owner'), $parentfolder,
$artefact->get('institution'), $group)) {
if ($existingid != $id) {
if ($collideaction == 'replace') {
log_debug('deleting ' . $existingid);
$copy = artefact_instance_from_id($existingid);
$copy->delete();
}
else {
json_reply('local', get_string('fileexists', 'artefact.file'));
}
}
}
$artefact->set('title', $name);
$artefact->set('description', $description);
$artefact->set('tags', preg_split("/\s*,\s*/", trim($tags)));
if ($group) {
$artefact->set('rolepermissions', (array) json_decode(param_variable('permissions')));
}
$artefact->commit();
json_reply(false, get_string('changessaved', 'artefact.file'));
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('IFRAME', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
$parentfolder = param_variable('parentfolder', null); // id of parent artefact
$parentfoldername = param_variable('parentfoldername', ''); // path to parent folder
$title = param_variable('title');
$description = param_variable('description', null);
$tags = param_variable('tags', null);
$uploadnumber = param_integer('uploadnumber'); // id of target iframe
$collideaction = param_variable('collideaction', 'fail');
$institution = param_alpha('institution', null);
$group = param_integer('group', null);
$result = new StdClass;
$result->uploadnumber = $uploadnumber;
$data = new StdClass;
if ($parentfolder) {
$data->parent = (int) $parentfolder;
}
$data->title = $title;
$data->description = $description;
$data->tags = $tags;
$data->owner = null;
require_once(get_config('docroot') . 'artefact/lib.php');
if ($parentfolder && !$USER->can_edit_artefact(artefact_instance_from_id($parentfolder))) {
$result->error = 'local';
$result->message = get_string('cannoteditfolder', 'artefact.file');
}
else {
if ($institution) {
$data->institution = $institution;
} else if ($group) {
require_once(get_config('libroot') . 'group.php');
if (!$parentfolder) {
$role = group_user_access($group);
if (!$role) {
$result->error = 'local';
$result->message = get_string('usernotingroup', 'mahara');
}
// Use default grouptype artefact permissions to check if the
// user can upload a file to the group's root directory
$permissions = group_get_default_artefact_permissions($group);
if (!$permissions[$role]->edit) {
$result->error = 'local';
$result->message = get_string('cannoteditfolder', 'artefact.file');
}
}
$data->group = $group;
$data->rolepermissions = (array) json_decode(param_variable('permissions'));
} else {
$data->owner = $USER->get('id');
}
}
$data->container = 0;
$data->locked = 0;
if (!isset($result->error)) {
if ($oldid = ArtefactTypeFileBase::file_exists($title, $data->owner, $parentfolder, $institution, $group)) {
if ($collideaction == 'replace') {
$obj = artefact_instance_from_id($oldid);
$obj->delete();
}
else {
// Hopefully this will happen rarely as filename clashes are
// detected in the javascript.
$result->error = 'fileexists';
$result->message = get_string('fileexistsonserver', 'artefact.file', $title);
}
}
}
if (!isset($result->error)) {
try {
ArtefactTypeFile::save_uploaded_file('userfile', $data);
}
catch (QuotaExceededException $e) {
prepare_upload_failed_message($result, $e, $parentfoldername, $title);
}
catch (UploadException $e) {
prepare_upload_failed_message($result, $e, $parentfoldername, $title);
}
}
if (!isset($result->error)) {
// Upload succeeded
$result->error = false;
if ($parentfoldername) {
$result->message = get_string('uploadoffiletofoldercomplete', 'artefact.file',
$title, $parentfoldername);
}
else {
$result->message = get_string('uploadoffilecomplete', 'artefact.file', $title);
}
}
$result->quota = $USER->get('quota');
$result->quotaused = $USER->get('quotaused');
$r = json_encode($result);
$frame = <<< EOF
<html><head><script>
<!--
function senduploadresult() {
var x = {$r};
parent.uploader.getresult(x);
}
// -->
</script></head>
<body onload="senduploadresult()"></body>
</html>
EOF;
header('Content-type: text/html');
echo $frame;
/**
* Helper function used above to minimise code duplication
*/
function prepare_upload_failed_message(&$result, $exception, $parentfoldername, $title) {
$result->error = 'local';
if ($parentfoldername) {
$result->message = get_string('uploadoffiletofolderfailed', 'artefact.file',
$title, $parentfoldername);
}
else {
$result->message = get_string('uploadoffilefailed', 'artefact.file', $title);
}
$result->message .= ': ' . $exception->getMessage();
}
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment