Commit ca308ba5 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1440916: Add attachment to forum posts

Allow one to attach files to forum topics/posts

Allow one to upload file to attach either to the user's section or to
group's section depending on which tab selected

Change-Id: I5feda5dd277ebbf70f6c494e2faa3b694ce1144d
parent a09778ad
......@@ -145,8 +145,8 @@ else {
}
}
// Check for images sitting in visible forum posts
if (!$imagevisible && $postid && $file instanceof ArtefactTypeImage) {
// Check for artefacts sitting in visible forum posts
if (!$imagevisible && $postid && $file instanceof ArtefactType) {
safe_require('interaction', 'forum');
$imagevisible = PluginInteractionForum::can_see_attached_file($file, $postid);
}
......
......@@ -27,7 +27,7 @@ var FileBrowser = (function($) {
alert('Filebrowser error 1');
}
if (self.config.select && typeof(self.form.submit) != 'function') {
// logWarn('Filebrowser error 2'); // Rename your submit element to something other than "submit".
console.log('Filebrowser error 2: Rename your submit element to something other than "submit"');
}
self.foldername = $('#' + self.id + '_foldername').val();
if (self.config.select) {
......@@ -364,6 +364,8 @@ var FileBrowser = (function($) {
edit_row.insertAfter(this_row);
edit_row.removeClass('hidden');
$(this).trigger('resize.bs.modal');
// Make the edit button close the form again
$(this).off();
$(this).on('click', function (e) {
......@@ -374,6 +376,7 @@ var FileBrowser = (function($) {
$(this).off();
$(this).on('click', self.edit_form);
}
$(this).trigger('resize.bs.modal');
return false;
});
......@@ -464,6 +467,9 @@ var FileBrowser = (function($) {
if (self.filedata[id].viewcount > 0) {
warn += get_string('fileappearsinviews') + ' ';
}
if (self.filedata[id].postcount > 0) {
warn += get_string('fileappearsinposts') + ' ';
}
if (self.filedata[id].skincount > 0) {
warn += get_string('fileappearsinskins') + ' ';
}
......@@ -1023,14 +1029,14 @@ var FileBrowser = (function($) {
self.config.editmeta = data.editmeta;
}
if (self.config.upload) {
if (data.disableedit && !$('#' + self.id + '_upload_container').hasClass('hidden')) {
if (data.disableedit == true && !$('#' + self.id + '_upload_container').hasClass('hidden')) {
$('#' + self.id + '_upload_container').addClass('hidden');
if ($('#createfolder').length) {
$('#createfolder').addClass('hidden');
}
$('#' + self.id + '_upload_disabled').removeClass('hidden');
}
else if ($('#' + self.id + '_upload_container').hasClass('hidden') && !data.disableedit) {
else if (data.disableedit == false) {
if (!self.tabdata || self.tabdata.upload) {
$('#' + self.id + '_upload_container').removeClass('hidden');
}
......@@ -1051,6 +1057,7 @@ var FileBrowser = (function($) {
if (data.tagblockhtml && $('#sb-tags').length) {
$('#sb-tags').html(data.tagblockhtml);
}
$('#' + self.id + '_filelist').find('.control-buttons button').first().trigger('resize.bs.modal');
self.browse_init();
}
else if (data.goto) {
......
......@@ -19,6 +19,7 @@ $string['archive'] = 'Archive';
$string['bytes'] = 'bytes';
$string['cannotviewfolder'] = 'You do not have permission to view the content of this folder.';
$string['cannoteditfolder'] = 'You do not have permission to add content to this folder.';
$string['cannotuploadtofolder'] = 'You do not have permission to upload content to this folder.';
$string['cannoteditfoldersubmitted'] = 'You cannot add content to a folder in a submitted page.';
$string['cannotremovefromsubmittedfolder'] = 'You cannot remove content from a folder in a submitted page.';
$string['cannotextractfilesubmitted'] = 'You cannot extract a file in a submitted page.';
......@@ -88,6 +89,7 @@ $string['File'] = 'File';
$string['fileadded'] = 'File selected';
$string['filealreadyindestination'] = 'The file you moved is already in that folder';
$string['fileappearsinviews'] = 'This file appears in one or more of your pages.';
$string['fileappearsinposts'] = 'This file appears in one or more of your forum posts.';
$string['fileattachedtoportfolioitems'] = array(
0 => 'This file is attached to %s other item in your portfolio.',
1 => 'This file is attached to %s other items in your portfolio.',
......@@ -96,6 +98,7 @@ $string['fileappearsinskins'] = 'This file is used as a background image in one
$string['profileiconattachedtoportfolioitems'] = 'This profile picture is attached to other items in your portfolio.';
$string['profileiconappearsinviews'] = 'This profile picture appears in one or more of your pages.';
$string['profileiconappearsinskins'] = 'This profile picture is used as a background image in one or more of your skins.';
$string['profileiconappearsinposts'] = 'This profile picture appears in one or more of your forum posts.';
$string['fileremoved'] = 'File removed';
$string['files'] = 'files';
$string['Files'] = 'Files';
......
......@@ -192,6 +192,7 @@ class PluginArtefactFile extends PluginArtefact {
'editfile',
'editfolder',
'fileappearsinviews',
'fileappearsinposts',
'fileattachedtoportfolioitems',
'fileappearsinskins',
'filewithnameexists',
......@@ -550,7 +551,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
SELECT
a.id, a.artefacttype, a.mtime, f.size, fi.orientation, a.title, a.description, a.license, a.licensor, a.licensorurl, a.locked, a.allowcomments, u.profileicon AS defaultprofileicon,
COUNT(DISTINCT c.id) AS childcount, COUNT (DISTINCT aa.artefact) AS attachcount, COUNT(DISTINCT va.view) AS viewcount, COUNT(DISTINCT s.id) AS skincount,
COUNT(DISTINCT api.id) AS profileiconcount';
COUNT(DISTINCT api.id) AS profileiconcount, COUNT(DISTINCT fpa.id) AS postcount';
$from = '
FROM {artefact} a
LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id
......@@ -560,6 +561,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id
LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.viewbgimg = a.id)
LEFT OUTER JOIN {interaction_forum_post_attachment} fpa ON fpa.attachment = a.id
LEFT OUTER JOIN {usr} u ON a.id = u.profileicon AND a.owner = u.id';
if (!empty($filters['artefacttype'])) {
......@@ -2409,6 +2411,9 @@ class ArtefactTypeImage extends ArtefactTypeFile {
if (isset($options['viewid'])) {
$url .= '&view=' . $options['viewid'];
}
if (isset($options['post'])) {
$url .= '&post=' . $options['post'];
}
if (isset($options['size'])) {
$url .= '&size=' . $options['size'];
}
......
......@@ -14,11 +14,12 @@ define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$result = get_records_sql_array('SELECT a.id, a.title, a.note, (u.profileicon = a.id) AS isdefault,
COUNT (DISTINCT aa.artefact) AS attachcount, COUNT(DISTINCT va.view) AS viewcount, COUNT(DISTINCT s.id) AS skincount
COUNT (DISTINCT aa.artefact) AS attachcount, COUNT(DISTINCT va.view) AS viewcount, COUNT(DISTINCT s.id) AS skincount, COUNT(DISTINCT fpa.id) AS postcount
FROM {artefact} a
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id
LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.viewbgimg = a.id)
LEFT OUTER JOIN {interaction_forum_post_attachment} fpa ON fpa.attachment = a.id
LEFT OUTER JOIN {usr} u ON (u.id = a.owner)
WHERE artefacttype = \'profileicon\'
AND a.owner = ?
......
......@@ -75,6 +75,7 @@ else {
$profileiconattachedtoportfolioitems = json_encode(get_string('profileiconattachedtoportfolioitems', 'artefact.file'));
$profileiconappearsinviews = json_encode(get_string('profileiconappearsinviews', 'artefact.file'));
$profileiconappearsinskins = json_encode(get_string('profileiconappearsinskins', 'artefact.file'));
$profileiconappearsinposts = json_encode(get_string('profileiconappearsinposts', 'artefact.file'));
$confirmdeletefile = json_encode(get_string('confirmdeletefile', 'artefact.file'));
$IJS = <<<EOF
......@@ -119,7 +120,7 @@ var table = new TableRenderer(
'type' : 'checkbox',
'class' : 'checkbox',
'name' : 'icons[' + rowdata.id + ']',
'value' : rowdata.attachcount + ',' + rowdata.viewcount + ',' + rowdata.skincount
'value' : rowdata.attachcount + ',' + rowdata.viewcount + ',' + rowdata.skincount + ',' + rowdata.postcount
};
if (!rowdata.id) {
options.disabled = 'disabled';
......@@ -163,7 +164,7 @@ jQuery(function($) {
$(form).find('input.checkbox').each(function () {
var id = $(this).prop('name').match(/\d+/)[0];
if ($(this).prop('checked')) {
var counts = $(this).prop('value').split(',', 3);
var counts = $(this).prop('value').split(',', 4);
var warn = '';
if (counts[0] > 0) {
warn += {$profileiconattachedtoportfolioitems} + ' ';
......@@ -174,6 +175,9 @@ jQuery(function($) {
if (counts[2] > 0) {
warn += {$profileiconappearsinskins} + ' ';
}
if (counts[3] > 0) {
warn += {$profileiconappearsinposts} + ' ';
}
if (warn != '') {
warn += {$confirmdeletefile};
if (!confirm(warn)) {
......
......@@ -845,6 +845,7 @@ abstract class ArtefactType implements IArtefactType {
// Detach any files from this artefact
delete_records_select('artefact_attachment', "artefact IN $idstr");
delete_records_select('interaction_forum_post_attachment', "attachment IN $idstr");
// Make sure that the artefacts are removed from any view blockinstances
require_once(get_config('docroot') . 'blocktype/lib.php');
......
......@@ -104,6 +104,19 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
$f->author->$uf = $f->$uf;
unset($f->$uf);
}
$f->filecount = 0;
if ($f->attachments = get_records_sql_array("
SELECT a.*, aff.size, aff.fileid, pa.post
FROM {artefact} a
JOIN {interaction_forum_post_attachment} pa ON pa.attachment = a.id
LEFT JOIN {artefact_file_files} aff ON aff.artefact = a.id
WHERE pa.post = ?", array($f->id))) {
$f->filecount = count($f->attachments);
safe_require('artefact', 'file');
foreach ($f->attachments as $file) {
$file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', array('id' => $file->id, 'post' => $f->id));
}
}
}
}
......
......@@ -91,7 +91,7 @@
<KEY NAME="forumfk" TYPE="foreign" FIELDS="forum" REFTABLE="interaction_instance" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="interaction_forum_edit">
<FIELDS>
<FIELD NAME="user" TYPE="int" NOTNULL="true" />
......@@ -103,5 +103,18 @@
<KEY NAME="postfk" TYPE="foreign" FIELDS="post" REFTABLE="interaction_forum_post" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="interaction_forum_post_attachment">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" SEQUENCE="true" NOTNULL="true" />
<FIELD NAME="post" TYPE="int" NOTNULL="true" />
<FIELD NAME="attachment" TYPE="int" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="postfk" TYPE="foreign" FIELDS="post" REFTABLE="interaction_forum_post" REFFIELDS="id" />
<KEY NAME="attachmentfk" TYPE="foreign" FIELDS="attachment" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -147,5 +147,18 @@ function xmldb_interaction_forum_upgrade($oldversion=0) {
}
}
if ($oldversion < 2018112800) {
$table = new XMLDBTable('interaction_forum_post_attachment');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('post', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('attachment', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('postfk', XMLDB_KEY_FOREIGN, array('post'), 'interaction_forum_post', array('id'));
$table->addKeyInfo('attachmentfk', XMLDB_KEY_FOREIGN, array('attachment'), 'artefact', array('id'));
if (!table_exists($table)) {
create_table($table);
}
}
return true;
}
......@@ -124,6 +124,7 @@ function deletepost_submit(Pieform $form, $values) {
// Delete embedded images in the forum post description
require_once('embeddedimage.php');
EmbeddedImage::delete_embedded_images('post', $postid);
delete_records('interaction_forum_post_attachment', 'post', $postid);
$SESSION->add_ok_msg(get_string('deletepostsuccess', 'interaction.forum'));
// Figure out which parent record to redirect us to. If the parent record is deleted,
......
......@@ -116,12 +116,15 @@ function deletetopic_submit(Pieform $form, $values) {
// Delete embedded images in the topic and its posts
require_once('embeddedimage.php');
EmbeddedImage::delete_embedded_images('topic', $topicid);
// Delete any post attachments for posts in this topic
delete_records_select('interaction_forum_post_attachment', "post IN (SELECT p.id FROM {interaction_forum_post} p WHERE p.topic = ?)", array($topicid));
// mark relevant posts as deleted
update_record(
'interaction_forum_post',
array('deleted' => 1),
array('topic' => $topicid)
);
$SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/view.php?id=' . $values['forum']);
}
......
......@@ -21,17 +21,19 @@ safe_require('interaction', 'forum');
require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('antispam.php');
safe_require('artefact', 'file');
define('SUBSECTIONHEADING', get_string('nameplural', 'interaction.forum'));
$postid = param_integer('id', 0);
$page = get_config('wwwroot') . 'interaction/forum/editpost.php';
if ($postid == 0) { // post reply
unset($postid);
$parentid = param_integer('parent');
$page .= '?parent=' . $parentid;
}
else { // edit post
$post = get_record_sql(
'SELECT p.subject, p.body, p.parent, p.topic, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . '
'SELECT p.subject, p.body, p.parent, p.topic, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', p.sent
FROM {interaction_forum_post} p
WHERE p.id = ?
AND p.deleted != 1
......@@ -42,6 +44,7 @@ else { // edit post
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $postid));
}
$parentid = $post->parent;
$page .= '?id=' . $postid;
}
if (!$parentid) {
......@@ -68,7 +71,6 @@ $parent = get_record_sql(
array(0, $parentid)
);
define('GROUP', $parent->group);
$membership = user_can_access_forum((int)$parent->forum);
......@@ -119,10 +121,27 @@ else { // edit post
$parent->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $parent->ctime);
$folder = param_integer('folder', 0);
$browse = (int) param_variable('browse', 0);
$highlight = null;
if ($file = param_integer('file', 0)) {
$highlight = array($file);
}
$instance = new InteractionForumInstance($parent->forum);
$currenttab = array('type' => 'user', 'id' => $USER->get('id'));
$mailsent = (isset($post) && !empty($post->sent)) ? true : false;
$editform = array(
'name' => 'editpost',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit',
'autofocus' => 'body',
'method' => 'post',
'jsform' => true,
'newiframeonsubmit' => true,
'jssuccesscallback' => 'editpost_callback',
'jserrorcallback' => 'editpost_callback',
'plugintype' => 'interaction',
'pluginname' => 'forum',
'configdirs' => array(get_config('libroot') . 'form/', get_config('docroot') . 'artefact/file/form/'),
'elements' => array(
'subject' => array(
'type' => 'text',
......@@ -145,13 +164,39 @@ $editform = array(
'maxlength' => 65536,
),
),
'filebrowser' => array(
'type' => 'filebrowser',
'title' => get_string('attachments', 'artefact.blog'),
'folder' => $folder,
'highlight' => $highlight,
'browse' => $browse,
'page' => $page . '&browse=1',
'browsehelp' => 'browsemyfiles',
'config' => array(
'upload' => true,
'uploadplaces' => array('user', 'group'),
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'),
'resizeonuploaduserdefault' => $USER->get_account_preference('resizeonuploaduserdefault'),
'createfolder' => false,
'edit' => true,
'noselect' => $mailsent,
'select' => true,
'alwaysopen' => false,
),
'defaultvalue' => $instance->attachment_id_list(isset($postid) ? $postid : 0),
'selectlistcallback' => 'artefact_get_records_by_id',
'selectcallback' => 'add_attachment',
'unselectcallback' => 'delete_attachment',
'tabs' => $currenttab,
),
'sendnow' => array(
'type' => 'switchbox',
'title' => get_string('sendnow', 'interaction.forum'),
'description' => get_string('sendnowdescription', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')),
'defaultvalue' => false,
),
'submit' => array(
'submitpost' => array(
'type' => 'submitcancel',
'class' => 'btn-primary',
'value' => array(
......@@ -196,9 +241,10 @@ function get_groupid_from_postid($postid) {
}
function editpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
global $USER, $SESSION, $parent;
require_once('embeddedimage.php');
$postid = param_integer('id');
$mailsent = get_field('interaction_forum_post', 'sent', 'id', $postid);
$groupid = get_groupid_from_postid($postid);
$newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'post', $postid, $groupid);
db_begin();
......@@ -220,9 +266,44 @@ function editpost_submit(Pieform $form, $values) {
)
);
}
// Attachments
$instance = new InteractionForumInstance($parent->forum);
$old = $instance->attachment_id_list($postid);
$new = is_array($values['filebrowser']) ? $values['filebrowser'] : array();
if (!empty($new) || !empty($old)) {
foreach ($old as $o) {
if (!in_array($o, $new)) {
try {
$instance->detach($postid, $o);
}
catch (ArtefactNotFoundException $e) {}
}
}
foreach ($new as $n) {
if (!in_array($n, $old)) {
try {
if (empty($mailsent)) {
$instance->attach($postid, $n);
}
}
catch (ArtefactNotFoundException $e) {}
}
}
}
db_commit();
$SESSION->add_ok_msg(get_string('editpostsuccess', 'interaction.forum'));
redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid);
$result = array(
'error' => false,
'message' => get_string('editpostsuccess', 'interaction.forum'),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid,
);
if ($form->submitted_by_js()) {
// Redirect back to the note page from within the iframe
$SESSION->add_ok_msg($result['message']);
$form->json_reply(PIEFORM_OK, $result, false);
}
$form->reply(PIEFORM_OK, $result);
}
function addpost_submit(Pieform $form, $values) {
......@@ -257,6 +338,30 @@ function addpost_submit(Pieform $form, $values) {
if (!empty($newbody) && $newbody != $post->body) {
set_field('interaction_forum_post', 'body', $newbody, 'id', $postid);
}
// Attachments
$forumid = get_field('interaction_forum_topic', 'forum', 'id', $post->topic);
$instance = new InteractionForumInstance($forumid);
$old = $instance->attachment_id_list($postid);
$new = is_array($values['filebrowser']) ? $values['filebrowser'] : array();
if (!empty($new) || !empty($old)) {
foreach ($old as $o) {
if (!in_array($o, $new)) {
try {
$instance->detach($postid, $o);
}
catch (ArtefactNotFoundException $e) {}
}
}
foreach ($new as $n) {
if (!in_array($n, $old)) {
try {
$instance->attach($postid, $n);
}
catch (ArtefactNotFoundException $e) {}
}
}
}
if ($sendnow == 0) {
$delay = get_config_plugin('interaction', 'forum', 'postdelay');
}
......@@ -266,16 +371,47 @@ function addpost_submit(Pieform $form, $values) {
if (!is_null($delay) && $delay == 0) {
PluginInteractionForum::interaction_forum_new_post(array($postid));
}
$SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
if (is_using_probation() && $post->parent) {
$parentposter = get_field('interaction_forum_post', 'poster', 'id', $post->parent);
vouch_for_probationary_user($parentposter);
}
redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid);
$result = array(
'error' => false,
'message' => get_string('addpostsuccess', 'interaction.forum'),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid,
);
if ($form->submitted_by_js()) {
// Redirect back to the note page from within the iframe
$SESSION->add_ok_msg($result['message']);
$form->json_reply(PIEFORM_OK, $result, false);
}
$form->reply(PIEFORM_OK, $result);
}
function add_attachment($attachmentid) {
global $parent, $postid;
$instance = new InteractionForumInstance($parent->forum);
if ($instance) {
$instance->attach($postid, $attachmentid);
}
}
function delete_note_attachment($attachmentid) {
global $parent, $postid;
$instance = new InteractionForumInstance($parent->forum);
if ($instance) {
$instance->detach($postid, $attachmentid);
}
}
$inlinejs = <<<EOF
function editpost_callback(form, data) {
editpost_filebrowser.callback(form, data);
};
EOF;
$smarty = smarty();
$smarty->assign('deleteduser', $poster->get('deleted'));
$smarty->assign('poster', $poster);
......@@ -289,7 +425,8 @@ if (isset($inlinejs)) {
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
}
if (isset($timeleft)) {
$smarty->assign('timeleft', $timeleft);
if (!isset($timeleft)) {
$timeleft = 0;
}
$smarty->assign('timeleft', $timeleft);
$smarty->display('interaction:forum:editpost.tpl');
......@@ -21,6 +21,7 @@ safe_require('interaction', 'forum');
require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('antispam.php');
safe_require('artefact', 'file');
require_once('embeddedimage.php');
define('SUBSECTIONHEADING', get_string('nameplural', 'interaction.forum'));
......@@ -28,13 +29,15 @@ $userid = $USER->get('id');
$topicid = param_integer('id', 0);
$returnto = param_alpha('returnto', 'topic');
$page = get_config('wwwroot') . 'interaction/forum/edittopic.php';
if ($topicid == 0) { // new topic
unset($topicid);
$forumid = param_integer('forum');
$page .= '?forum=' . $forumid;
}
else { // edit topic
$topic = get_record_sql(
'SELECT p.subject, p.id AS postid, p.body, p.poster, p.topic AS id, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.sticky, t.closed, f.id AS forum
'SELECT p.subject, p.id AS postid, p.body, p.poster, p.topic AS id, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.sticky, t.closed, f.id AS forum, p.sent
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
......@@ -43,7 +46,7 @@ else { // edit topic
array($topicid)
);
$forumid = $topic->forum;
$page .= '?id=' . $topic->id;
if (!$topic) {
throw new NotFoundException(get_string('cantfindtopic', 'interaction.forum', $topicid));
}
......@@ -102,10 +105,27 @@ else { // edit topic
}
}
$folder = param_integer('folder', 0);
$browse = (int) param_variable('browse', 0);
$highlight = null;
if ($file = param_integer('file', 0)) {
$highlight = array($file);
}
$instance = new InteractionForumInstance($forumid);
$currenttab = array('type' => 'user', 'id' => $USER->get('id'));
$mailsent = (isset($topic) && !empty($topic->sent)) ? true : false;
$editform = array(
'name' => isset($topic) ? 'edittopic' : 'addtopic',
'method' => 'post',
'autofocus' => isset($topic) ? 'body' : 'subject',
'name' => 'edittopic',
'successcallback' => isset($topic) ? 'edittopic_submit' : 'addtopic_submit',
'method' => 'post',
'jsform' => true,
'newiframeonsubmit' => true,
'jssuccesscallback' => 'edittopic_callback',
'jserrorcallback' => 'edittopic_callback',
'plugintype' => 'interaction',
'pluginname' => 'forum',
'configdirs' => array(get_config('libroot') . 'form/', get_config('docroot') . 'artefact/file/form/'),
'elements' => array(
'subject' => array(
'type' => 'text',
......@@ -127,6 +147,32 @@ $editform = array(
'maxlength' => 65536,
),
),
'filebrowser' => array(
'type' => 'filebrowser',
'title' => get_string('attachments', 'artefact.blog'),
'folder' => $folder,
'highlight' => $highlight,
'browse' => $browse,
'page' => $page . '&browse=1',
'browsehelp' => 'browsemyfiles',
'config' => array(
'upload' => true,
'uploadplaces' => array('user', 'group'),
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'),
'resizeonuploaduserdefault' => $USER->get_account_preference('resizeonuploaduserdefault'),
'createfolder' => false,