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 { ...@@ -145,8 +145,8 @@ else {
} }
} }
// Check for images sitting in visible forum posts // Check for artefacts sitting in visible forum posts
if (!$imagevisible && $postid && $file instanceof ArtefactTypeImage) { if (!$imagevisible && $postid && $file instanceof ArtefactType) {
safe_require('interaction', 'forum'); safe_require('interaction', 'forum');
$imagevisible = PluginInteractionForum::can_see_attached_file($file, $postid); $imagevisible = PluginInteractionForum::can_see_attached_file($file, $postid);
} }
......
...@@ -27,7 +27,7 @@ var FileBrowser = (function($) { ...@@ -27,7 +27,7 @@ var FileBrowser = (function($) {
alert('Filebrowser error 1'); alert('Filebrowser error 1');
} }
if (self.config.select && typeof(self.form.submit) != 'function') { 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(); self.foldername = $('#' + self.id + '_foldername').val();
if (self.config.select) { if (self.config.select) {
...@@ -364,6 +364,8 @@ var FileBrowser = (function($) { ...@@ -364,6 +364,8 @@ var FileBrowser = (function($) {
edit_row.insertAfter(this_row); edit_row.insertAfter(this_row);
edit_row.removeClass('hidden'); edit_row.removeClass('hidden');
$(this).trigger('resize.bs.modal');
// Make the edit button close the form again // Make the edit button close the form again
$(this).off(); $(this).off();
$(this).on('click', function (e) { $(this).on('click', function (e) {
...@@ -374,6 +376,7 @@ var FileBrowser = (function($) { ...@@ -374,6 +376,7 @@ var FileBrowser = (function($) {
$(this).off(); $(this).off();
$(this).on('click', self.edit_form); $(this).on('click', self.edit_form);
} }
$(this).trigger('resize.bs.modal');
return false; return false;
}); });
...@@ -464,6 +467,9 @@ var FileBrowser = (function($) { ...@@ -464,6 +467,9 @@ var FileBrowser = (function($) {
if (self.filedata[id].viewcount > 0) { if (self.filedata[id].viewcount > 0) {
warn += get_string('fileappearsinviews') + ' '; warn += get_string('fileappearsinviews') + ' ';
} }
if (self.filedata[id].postcount > 0) {
warn += get_string('fileappearsinposts') + ' ';
}
if (self.filedata[id].skincount > 0) { if (self.filedata[id].skincount > 0) {
warn += get_string('fileappearsinskins') + ' '; warn += get_string('fileappearsinskins') + ' ';
} }
...@@ -1023,14 +1029,14 @@ var FileBrowser = (function($) { ...@@ -1023,14 +1029,14 @@ var FileBrowser = (function($) {
self.config.editmeta = data.editmeta; self.config.editmeta = data.editmeta;
} }
if (self.config.upload) { 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'); $('#' + self.id + '_upload_container').addClass('hidden');
if ($('#createfolder').length) { if ($('#createfolder').length) {
$('#createfolder').addClass('hidden'); $('#createfolder').addClass('hidden');
} }
$('#' + self.id + '_upload_disabled').removeClass('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) { if (!self.tabdata || self.tabdata.upload) {
$('#' + self.id + '_upload_container').removeClass('hidden'); $('#' + self.id + '_upload_container').removeClass('hidden');
} }
...@@ -1051,6 +1057,7 @@ var FileBrowser = (function($) { ...@@ -1051,6 +1057,7 @@ var FileBrowser = (function($) {
if (data.tagblockhtml && $('#sb-tags').length) { if (data.tagblockhtml && $('#sb-tags').length) {
$('#sb-tags').html(data.tagblockhtml); $('#sb-tags').html(data.tagblockhtml);
} }
$('#' + self.id + '_filelist').find('.control-buttons button').first().trigger('resize.bs.modal');
self.browse_init(); self.browse_init();
} }
else if (data.goto) { else if (data.goto) {
......
...@@ -19,6 +19,7 @@ $string['archive'] = 'Archive'; ...@@ -19,6 +19,7 @@ $string['archive'] = 'Archive';
$string['bytes'] = 'bytes'; $string['bytes'] = 'bytes';
$string['cannotviewfolder'] = 'You do not have permission to view the content of this folder.'; $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['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['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['cannotremovefromsubmittedfolder'] = 'You cannot remove content from a folder in a submitted page.';
$string['cannotextractfilesubmitted'] = 'You cannot extract a file in a submitted page.'; $string['cannotextractfilesubmitted'] = 'You cannot extract a file in a submitted page.';
...@@ -88,6 +89,7 @@ $string['File'] = 'File'; ...@@ -88,6 +89,7 @@ $string['File'] = 'File';
$string['fileadded'] = 'File selected'; $string['fileadded'] = 'File selected';
$string['filealreadyindestination'] = 'The file you moved is already in that folder'; $string['filealreadyindestination'] = 'The file you moved is already in that folder';
$string['fileappearsinviews'] = 'This file appears in one or more of your pages.'; $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( $string['fileattachedtoportfolioitems'] = array(
0 => 'This file is attached to %s other item in your portfolio.', 0 => 'This file is attached to %s other item in your portfolio.',
1 => 'This file is attached to %s other items 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 ...@@ -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['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['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['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['fileremoved'] = 'File removed';
$string['files'] = 'files'; $string['files'] = 'files';
$string['Files'] = 'Files'; $string['Files'] = 'Files';
......
...@@ -192,6 +192,7 @@ class PluginArtefactFile extends PluginArtefact { ...@@ -192,6 +192,7 @@ class PluginArtefactFile extends PluginArtefact {
'editfile', 'editfile',
'editfolder', 'editfolder',
'fileappearsinviews', 'fileappearsinviews',
'fileappearsinposts',
'fileattachedtoportfolioitems', 'fileattachedtoportfolioitems',
'fileappearsinskins', 'fileappearsinskins',
'filewithnameexists', 'filewithnameexists',
...@@ -550,7 +551,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType { ...@@ -550,7 +551,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
SELECT 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, 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 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 = '
FROM {artefact} a FROM {artefact} a
LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id
...@@ -560,6 +561,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType { ...@@ -560,6 +561,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id 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 {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 {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'; LEFT OUTER JOIN {usr} u ON a.id = u.profileicon AND a.owner = u.id';
if (!empty($filters['artefacttype'])) { if (!empty($filters['artefacttype'])) {
...@@ -2409,6 +2411,9 @@ class ArtefactTypeImage extends ArtefactTypeFile { ...@@ -2409,6 +2411,9 @@ class ArtefactTypeImage extends ArtefactTypeFile {
if (isset($options['viewid'])) { if (isset($options['viewid'])) {
$url .= '&view=' . $options['viewid']; $url .= '&view=' . $options['viewid'];
} }
if (isset($options['post'])) {
$url .= '&post=' . $options['post'];
}
if (isset($options['size'])) { if (isset($options['size'])) {
$url .= '&size=' . $options['size']; $url .= '&size=' . $options['size'];
} }
......
...@@ -14,11 +14,12 @@ define('JSON', 1); ...@@ -14,11 +14,12 @@ define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php'); 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, $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 FROM {artefact} a
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id 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 {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 {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) LEFT OUTER JOIN {usr} u ON (u.id = a.owner)
WHERE artefacttype = \'profileicon\' WHERE artefacttype = \'profileicon\'
AND a.owner = ? AND a.owner = ?
......
...@@ -75,6 +75,7 @@ else { ...@@ -75,6 +75,7 @@ else {
$profileiconattachedtoportfolioitems = json_encode(get_string('profileiconattachedtoportfolioitems', 'artefact.file')); $profileiconattachedtoportfolioitems = json_encode(get_string('profileiconattachedtoportfolioitems', 'artefact.file'));
$profileiconappearsinviews = json_encode(get_string('profileiconappearsinviews', 'artefact.file')); $profileiconappearsinviews = json_encode(get_string('profileiconappearsinviews', 'artefact.file'));
$profileiconappearsinskins = json_encode(get_string('profileiconappearsinskins', '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')); $confirmdeletefile = json_encode(get_string('confirmdeletefile', 'artefact.file'));
$IJS = <<<EOF $IJS = <<<EOF
...@@ -119,7 +120,7 @@ var table = new TableRenderer( ...@@ -119,7 +120,7 @@ var table = new TableRenderer(
'type' : 'checkbox', 'type' : 'checkbox',
'class' : 'checkbox', 'class' : 'checkbox',
'name' : 'icons[' + rowdata.id + ']', 'name' : 'icons[' + rowdata.id + ']',
'value' : rowdata.attachcount + ',' + rowdata.viewcount + ',' + rowdata.skincount 'value' : rowdata.attachcount + ',' + rowdata.viewcount + ',' + rowdata.skincount + ',' + rowdata.postcount
}; };
if (!rowdata.id) { if (!rowdata.id) {
options.disabled = 'disabled'; options.disabled = 'disabled';
...@@ -163,7 +164,7 @@ jQuery(function($) { ...@@ -163,7 +164,7 @@ jQuery(function($) {
$(form).find('input.checkbox').each(function () { $(form).find('input.checkbox').each(function () {
var id = $(this).prop('name').match(/\d+/)[0]; var id = $(this).prop('name').match(/\d+/)[0];
if ($(this).prop('checked')) { if ($(this).prop('checked')) {
var counts = $(this).prop('value').split(',', 3); var counts = $(this).prop('value').split(',', 4);
var warn = ''; var warn = '';
if (counts[0] > 0) { if (counts[0] > 0) {
warn += {$profileiconattachedtoportfolioitems} + ' '; warn += {$profileiconattachedtoportfolioitems} + ' ';
...@@ -174,6 +175,9 @@ jQuery(function($) { ...@@ -174,6 +175,9 @@ jQuery(function($) {
if (counts[2] > 0) { if (counts[2] > 0) {
warn += {$profileiconappearsinskins} + ' '; warn += {$profileiconappearsinskins} + ' ';
} }
if (counts[3] > 0) {
warn += {$profileiconappearsinposts} + ' ';
}
if (warn != '') { if (warn != '') {
warn += {$confirmdeletefile}; warn += {$confirmdeletefile};
if (!confirm(warn)) { if (!confirm(warn)) {
......
...@@ -845,6 +845,7 @@ abstract class ArtefactType implements IArtefactType { ...@@ -845,6 +845,7 @@ abstract class ArtefactType implements IArtefactType {
// Detach any files from this artefact // Detach any files from this artefact
delete_records_select('artefact_attachment', "artefact IN $idstr"); 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 // Make sure that the artefacts are removed from any view blockinstances
require_once(get_config('docroot') . 'blocktype/lib.php'); require_once(get_config('docroot') . 'blocktype/lib.php');
......
...@@ -104,6 +104,19 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype { ...@@ -104,6 +104,19 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
$f->author->$uf = $f->$uf; $f->author->$uf = $f->$uf;
unset($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 @@ ...@@ -91,7 +91,7 @@
<KEY NAME="forumfk" TYPE="foreign" FIELDS="forum" REFTABLE="interaction_instance" REFFIELDS="id" /> <KEY NAME="forumfk" TYPE="foreign" FIELDS="forum" REFTABLE="interaction_instance" REFFIELDS="id" />
</KEYS> </KEYS>
</TABLE> </TABLE>
<TABLE NAME="interaction_forum_edit"> <TABLE NAME="interaction_forum_edit">
<FIELDS> <FIELDS>
<FIELD NAME="user" TYPE="int" NOTNULL="true" /> <FIELD NAME="user" TYPE="int" NOTNULL="true" />
...@@ -103,5 +103,18 @@ ...@@ -103,5 +103,18 @@
<KEY NAME="postfk" TYPE="foreign" FIELDS="post" REFTABLE="interaction_forum_post" REFFIELDS="id" /> <KEY NAME="postfk" TYPE="foreign" FIELDS="post" REFTABLE="interaction_forum_post" REFFIELDS="id" />
</KEYS> </KEYS>
</TABLE> </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> </TABLES>
</XMLDB> </XMLDB>
...@@ -147,5 +147,18 @@ function xmldb_interaction_forum_upgrade($oldversion=0) { ...@@ -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; return true;
} }
...@@ -124,6 +124,7 @@ function deletepost_submit(Pieform $form, $values) { ...@@ -124,6 +124,7 @@ function deletepost_submit(Pieform $form, $values) {
// Delete embedded images in the forum post description // Delete embedded images in the forum post description
require_once('embeddedimage.php'); require_once('embeddedimage.php');
EmbeddedImage::delete_embedded_images('post', $postid); EmbeddedImage::delete_embedded_images('post', $postid);
delete_records('interaction_forum_post_attachment', 'post', $postid);
$SESSION->add_ok_msg(get_string('deletepostsuccess', 'interaction.forum')); $SESSION->add_ok_msg(get_string('deletepostsuccess', 'interaction.forum'));
// Figure out which parent record to redirect us to. If the parent record is deleted, // 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) { ...@@ -116,12 +116,15 @@ function deletetopic_submit(Pieform $form, $values) {
// Delete embedded images in the topic and its posts // Delete embedded images in the topic and its posts
require_once('embeddedimage.php'); require_once('embeddedimage.php');
EmbeddedImage::delete_embedded_images('topic', $topicid); 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 // mark relevant posts as deleted
update_record( update_record(
'interaction_forum_post', 'interaction_forum_post',
array('deleted' => 1), array('deleted' => 1),
array('topic' => $topicid) array('topic' => $topicid)
); );
$SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum')); $SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/view.php?id=' . $values['forum']); redirect('/interaction/forum/view.php?id=' . $values['forum']);
} }
......
...@@ -21,17 +21,19 @@ safe_require('interaction', 'forum'); ...@@ -21,17 +21,19 @@ safe_require('interaction', 'forum');
require_once('group.php'); require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php'); require_once(get_config('docroot') . 'interaction/lib.php');
require_once('antispam.php'); require_once('antispam.php');
safe_require('artefact', 'file');
define('SUBSECTIONHEADING', get_string('nameplural', 'interaction.forum')); define('SUBSECTIONHEADING', get_string('nameplural', 'interaction.forum'));
$postid = param_integer('id', 0); $postid = param_integer('id', 0);
$page = get_config('wwwroot') . 'interaction/forum/editpost.php';
if ($postid == 0) { // post reply if ($postid == 0) { // post reply
unset($postid); unset($postid);
$parentid = param_integer('parent'); $parentid = param_integer('parent');
$page .= '?parent=' . $parentid;
} }
else { // edit post else { // edit post
$post = get_record_sql( $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 FROM {interaction_forum_post} p
WHERE p.id = ? WHERE p.id = ?
AND p.deleted != 1 AND p.deleted != 1
...@@ -42,6 +44,7 @@ else { // edit post ...@@ -42,6 +44,7 @@ else { // edit post
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $postid)); throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $postid));
} }
$parentid = $post->parent; $parentid = $post->parent;
$page .= '?id=' . $postid;
} }
if (!$parentid) { if (!$parentid) {
...@@ -68,7 +71,6 @@ $parent = get_record_sql( ...@@ -68,7 +71,6 @@ $parent = get_record_sql(
array(0, $parentid) array(0, $parentid)
); );
define('GROUP', $parent->group); define('GROUP', $parent->group);
$membership = user_can_access_forum((int)$parent->forum); $membership = user_can_access_forum((int)$parent->forum);
...@@ -119,10 +121,27 @@ else { // edit post ...@@ -119,10 +121,27 @@ else { // edit post
$parent->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $parent->ctime); $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( $editform = array(
'name' => 'editpost', 'name' => 'editpost',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit', '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( 'elements' => array(
'subject' => array( 'subject' => array(
'type' => 'text', 'type' => 'text',
...@@ -145,13 +164,39 @@ $editform = array( ...@@ -145,13 +164,39 @@ $editform = array(
'maxlength' => 65536, '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( 'sendnow' => array(
'type' => 'switchbox', 'type' => 'switchbox',
'title' => get_string('sendnow', 'interaction.forum'), 'title' => get_string('sendnow', 'interaction.forum'),
'description' => get_string('sendnowdescription', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')), 'description' => get_string('sendnowdescription', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')),
'defaultvalue' => false, 'defaultvalue' => false,
), ),
'submit' => array( 'submitpost' => array(
'type' => 'submitcancel', 'type' => 'submitcancel',
'class' => 'btn-primary', 'class' => 'btn-primary',
'value' => array( 'value' => array(
...@@ -196,9 +241,10 @@ function get_groupid_from_postid($postid) { ...@@ -196,9 +241,10 @@ function get_groupid_from_postid($postid) {
} }
function editpost_submit(Pieform $form, $values) { function editpost_submit(Pieform $form, $values) {
global $USER, $SESSION; global $USER, $SESSION, $parent;
require_once('embeddedimage.php'); require_once('embeddedimage.php');
$postid = param_integer('id'); $postid = param_integer('id');
$mailsent = get_field('interaction_forum_post', 'sent', 'id', $postid);
$groupid = get_groupid_from_postid($postid); $groupid = get_groupid_from_postid($postid);
$newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'post', $postid, $groupid); $newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'post', $postid, $groupid);
db_begin(); db_begin();
...@@ -220,9 +266,44 @@ function editpost_submit(Pieform $form, $values) { ...@@ -220,9 +266,44 @@ function editpost_submit(Pieform $form, $values) {