Commit 2c54370c authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow tutors to upload an attachment with view feedback

parent 612919a3
......@@ -312,7 +312,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
// Number of subdirectories to create under $artefactfileroot (should be configurable).
static $artefactfilesubdirs = 256;
private static function get_file_directory($id) {
public static function get_file_directory($id) {
return self::$artefactfileroot . $id % self::$artefactfilesubdirs;
}
......@@ -405,6 +405,8 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return $error;
}
public static function get_admin_files($public) {
if ($public) {
$foldersql = 'parent = ' . ArtefactTypeFolder::admin_public_folder_id();
......@@ -428,6 +430,8 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return;
}
$file = $this->get_path();
// Detach this file from any view feedback
set_field('view_feedback', 'attachment', null, 'attachment', $this->id);
if (is_file($file)) {
$size = filesize($file);
unlink($file);
......@@ -599,24 +603,30 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
return $folderid;
}
public static function get_folder_by_name($name, $parentfolderid=null) {
global $USER;
public static function get_folder_by_name($name, $parentfolderid=null, $userid=null) {
if (empty($userid)) {
global $USER;
$userid = $USER->get('id');
}
$prefix = get_config('dbprefix');
$parentclause = $parentfolderid ? 'parent = ' . $parentfolderid : 'parent IS NULL';
return get_record_sql('SELECT * FROM ' . $prefix . 'artefact
WHERE title = ? AND ' . $parentclause . ' AND owner = ' . $USER->get('id') . "
WHERE title = ? AND ' . $parentclause . ' AND owner = ' . $userid . "
AND artefacttype = 'folder'", array($name));
}
// Get the id of a folder, creating the folder if necessary
public static function get_folder_id($name, $description, $parentfolderid=null) {
global $USER;
if (!$record = self::get_folder_by_name($name, $parentfolderid)) {
public static function get_folder_id($name, $description, $parentfolderid=null, $userid=null) {
if (empty($userid)) {
global $USER;
$userid = $USER->get('id');
}
if (!$record = self::get_folder_by_name($name, $parentfolderid, $userid)) {
$data = new StdClass;
$data->title = $name;
$data->description = $description;
$f = new ArtefactTypeFolder(0, $data);
$f->set('owner', $USER->get('id'));
$f->set('owner', $userid);
$f->set('parent', $parentfolderid);
$f->commit();
return $f->get('id');
......
......@@ -367,10 +367,15 @@ $string['addfeedbackfailed'] = 'Add feedback failed';
$string['addtowatchlist'] = 'Add %s to watchlist';
$string['addtowatchlistwithchildren'] = 'Add entire %s contents to watchlist';
$string['alreadyinwatchlist'] = 'This %s is already in your watchlist';
$string['attachedfileaddedtofolder'] = "The attached file %s has been added to your '%s' folder.";
$string['complaint'] = 'Complaint';
$string['date'] = 'Date';
$string['feedback'] = 'Feedback';
$string['feedbackattachdirname'] = 'assessmentfiles';
$string['feedbackattachdirdesc'] = 'Files attached to view assessments';
$string['feedbackattachmessage'] = 'The attached file has been added to your %s folder';
$string['feedbackmadeprivate'] = 'Feedback changed to private';
$string['feedbackonviewbytutorofcommunity'] = 'Feedback on %s by %s of %s';
$string['feedbacksubmitted'] = 'Feedback submitted';
$string['makepublic'] = 'Make public';
$string['nopublicfeedback'] = 'No public feedback';
......
......@@ -17,7 +17,7 @@
<div id="publicfeedback">
<table id="feedbacktable">
<thead>
<tr><th colspan=4>{str tag=feedback}</th></tr>
<tr><th colspan=5>{str tag=feedback}</th></tr>
</thead>
</table>
</div>
......
<?php
/**
* This program is part of Mahara
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Richard Mansfield <richard.mansfield@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
//safe_require('artefact', 'file');
$viewid = param_integer('view');
$message = param_variable('message', '');
$public = (int) param_boolean('public', false);
$filename = param_variable('filename');
// Upload the file into the view owner's my files area. This file
// will add to the view owner's quota, but saving the file will not
// fail if the quota is exceeded.
// Community name, view title, feedback number?
$prefix = get_config('dbprefix');
$viewdata = get_record_sql('
SELECT
v.title, v.owner, c.name
FROM ' . $prefix . 'view v
INNER JOIN ' . $prefix . 'community c ON v.submittedto = c.id
WHERE v.id = ' . $viewid, '');
$page = get_config('wwwroot') . 'view/view.php?view=' . $viewid;
require_once('uploadmanager.php');
$um = new upload_manager('attachment');
if ($error = $um->preprocess_file()) {
// Should do something more sensible here, like display the error
// next to the feedback submit button.
log_info($error, false, false);
redirect($page);
}
$size = $um->file['size'];
safe_require('artefact', 'file');
$folderid = ArtefactTypeFolder::get_folder_id(get_string('feedbackattachdirname'),
get_string('feedbackattachdirdesc'),
null, $viewdata->owner);
// Create a new file object
$data = (object) array('owner' => $viewdata->owner,
'parent' => $folderid,
'size' => $size,
'title' => $filename,
'description' => get_string('feedbackonviewbytutorofcommunity', 'mahara',
$viewdata->title, display_name($USER), $viewdata->name));
$f = ArtefactTypeFile::new_file($um->file['tmp_name'], $data);
$f->commit();
$fileid = $f->get('id');
if ($error = $um->save_file(ArtefactTypeFile::get_file_directory($fileid) , $fileid)) {
$f->delete();
log_info($error, false, false);
redirect($page);
}
else {
//$USER->quota_add($size);
// Just add to the usr table directly.
$ownerquotaused = get_field('usr', 'quotaused', 'id', $viewdata->owner);
set_field('usr', 'quotaused', $ownerquotaused + $size, 'id', $viewdata->owner);
}
global $USER;
$tutor = $USER->get('id');
$data = (object) array('view' => $viewid,
'author' => $tutor,
'message' => $message,
'attachment' => $fileid,
'ctime' => db_format_timestamp(time()),
'public' => $public);
if (!insert_record('view_feedback', $data)) {
$f->delete();
}
redirect(get_config('wwwroot') . 'view/view.php?view=' . $viewid);
?>
......@@ -39,44 +39,43 @@ $offset = param_integer('offset', 0);
$prefix = get_config('dbprefix');
if ($artefact) {
$table = 'artefact';
$artefactfield = 'artefact';
$whereartefactclause = ' AND artefact = ' . $artefact;
$owner = get_field('artefact', 'owner', 'id', $artefact);
$publiconly = ($owner != $USER->get('id'));
$feedback = get_records_sql_array('SELECT id, author, ctime, message, public
FROM ' . $prefix . 'artefact_feedback
WHERE view = ' . $view . ' AND artefact = ' . $artefact . ($publiconly ? ' AND public = 1' : '') . '
ORDER BY id DESC', '', $offset, $limit);
$count = count_records('artefact_feedback', 'view', $view, 'artefact', $artefact);
}
else {
$table = 'view';
$artefactfield = null;
$whereartefactclause = '';
$owner = get_field('view', 'owner', 'id', $view);
$publiconly = ($owner != $USER->get('id'));
$feedback = get_records_sql_array('
SELECT
f.id, f.author, f.ctime, f.message, f.public, f.attachment, a.title
FROM ' . $prefix . 'view_feedback f
LEFT OUTER JOIN ' . $prefix . 'artefact a ON f.attachment = a.id
WHERE view = ' . $view . ($publiconly ? ' AND f.public = 1' : '') . '
ORDER BY id DESC', '', $offset, $limit);
$count = count_records('artefact_feedback', 'view', $view);
}
$owner = get_field($table, 'owner', 'id', $artefact ? $artefact : $view);
$table .= '_feedback';
if ($owner == $USER->get('id')) {
$count = count_records($table, 'view', $view, $artefactfield, $artefact);
$publicclause = '';
}
else {
$count = count_records($table, 'public', 1, 'view', $view, $artefactfield, $artefact);
$publicclause = ' AND public = 1';
}
$feedback = get_records_sql_array('SELECT id, author, ctime, message, public
FROM ' . $prefix . $table . '
WHERE view = ' . $view . $whereartefactclause . $publicclause . '
ORDER BY id DESC', '', $offset, $limit);
$data = array();
if ($feedback) {
foreach ($feedback as $record) {
$data[] = array(
$d = array(
'id' => $record->id,
'ownedbythisuser' => ( get_field('view', 'owner', 'id', $view) == $USER->get('id') ? true : false ),
'table' => $table,
'name' => display_name($record->author),
'date' => format_date(strtotime($record->ctime), 'strftimedate'),
'message' => $record->message,
'public' => $record->public
);
if (!empty($record->attachment)) {
$d['attachid'] = $record->attachment;
$d['attachtitle'] = $record->title;
}
$data[] = $d;
}
}
......
......@@ -69,6 +69,20 @@ else {
define('TITLE', $view->get('title'));
$jsartefact = 'undefined';
$content = $view->render();
global $USER;
if (record_exists('community_member',
'community', $view->get('submittedto'),
'member', $USER->get('id'),
'tutor', 1)) {
// The user is a tutor of the community that this view has
// been submitted to, and is entitled to upload an additional
// file when submitting feedback.
$tutorfilefeedbackformrow = "TR(null, TH(null, LABEL(null, '" . get_string('attachfile') . "'))),"
. "TR(null, TD(null, INPUT({'type':'file', 'name':'attachment'}))),";
}
}
if (empty($tutorfilefeedbackformrow)) {
$tutorfilefeedbackformrow = '';
}
$getstring = quotestrings(array('mahara' => array(
......@@ -79,6 +93,7 @@ $getstring = quotestrings(array('mahara' => array(
$thing = $artefactid ? 'artefact' : 'view';
$getstring['addtowatchlist'] = "'" . get_string('addtowatchlist', 'mahara', get_string($thing)) . "'";
$getstring['addtowatchlistwithchildren'] = "'" . get_string('addtowatchlistwithchildren', 'mahara', ucfirst(get_string($thing))) . "'";
$getstring['feedbackattachmessage'] = "'(" . get_string('feedbackattachmessage', 'mahara', get_string('feedbackattachdirname')) . ")'";
$javascript = <<<EOF
......@@ -91,26 +106,37 @@ function feedbackform() {
}
var form = FORM({'id':'menuform','method':'post'});
submitfeedback = function () {
// @todo add support for attached files when user is a tutor.
var data = {'view':view,
'message':form.message.value,
'public':form.public.checked};
if (artefact) {
data.artefact = artefact;
if (form.attachment.value) {
updateNodeAttributes(form, {'enctype':'multipart/form-data',
'encoding':'multipart/form-data',
'action':'feedbackattachment.php', 'target':''});
appendChildNodes(form, INPUT({'type':'hidden', 'name':'view', 'value':view}));
appendChildNodes(form, INPUT({'type':'hidden', 'name':'filename',
'value':basename(form.attachment.value)}));
form.submit();
}
sendjsonrequest('addfeedback.json.php', data, function () {
else {
var data = {'view':view,
'message':form.message.value,
'public':form.public.checked};
if (artefact) {
data.artefact = artefact;
}
sendjsonrequest('addfeedback.json.php', data, function () {
removeElement('menuform');
feedbacklist.doupdate();
});
return false;
return false;
}
}
appendChildNodes(form,
TABLE({'border':0, 'cellspacing':0},
TABLE({'border':0, 'cellspacing':0, 'class':'maharatable'},
TBODY(null,
TR(null, TH(null, LABEL(null, {$getstring['message']}))),
TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
TR(null, TH(null, LABEL(null, {$getstring['makepublic']}),
INPUT({'type':'checkbox', 'class':'checkbox', 'name':'public'}))),
{$tutorfilefeedbackformrow}
TR(null, TD(null,
INPUT({'type':'button', 'class':'button',
'value':{$getstring['placefeedback']},
......@@ -178,7 +204,12 @@ var feedbacklist = new TableRenderer(
'feedbacktable',
'getfeedback.json.php',
[
'message',
function (r) {
if (r.attachid && r.ownedbythisuser) {
return TD(null, r.message, DIV(null, {$getstring['feedbackattachmessage']}));
}
return TD(null, r.message);
},
'name',
'date',
function (r) {
......@@ -204,6 +235,13 @@ var feedbacklist = new TableRenderer(
}
return TD(null, '(' + get_string('private') + ')');
},
function (r) {
if (r.attachid) {
return TD(null, A({'href':config.wwwroot + 'artefact/file/download.php?file=' + r.attachid},
r.attachtitle));
}
return TD(null);
}
]
);
......
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