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

Use form instead of link to delete blogs (bug #714967)



Change-Id: Ida95847279db5a2a25201ebad8913704fdd852e6
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 749feb37
......@@ -37,18 +37,7 @@ safe_require('artefact', 'blog');
define('TITLE', get_string('blogs','artefact.blog'));
if ($delete = param_integer('delete', 0)) {
form_validate(param_alphanum('sesskey', null));
$blog = artefact_instance_from_id($delete);
if ($blog instanceof ArtefactTypeBlog) {
$blog->check_permission();
if ($blog->get('locked')) {
$SESSION->add_error_msg(get_string('submittedforassessment', 'view'));
}
else {
$blog->delete();
$SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
}
}
ArtefactTypeBlog::delete_form($delete);
}
$blogs = (object) array(
......@@ -66,4 +55,16 @@ $smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('INLINEJAVASCRIPT', 'addLoadEvent(function() {' . $blogs->pagination_js . '});');
$smarty->display('artefact:blog:index.tpl');
?>
function delete_blog_submit(Pieform $form, $values) {
global $SESSION;
$blog = new ArtefactTypeBlog($values['delete']);
$blog->check_permission();
if ($blog->get('locked')) {
$SESSION->add_error_msg(get_string('submittedforassessment', 'view'));
}
else {
$blog->delete();
$SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
}
redirect('/artefact/blog/');
}
......@@ -287,6 +287,12 @@ class ArtefactTypeBlog extends ArtefactType {
ORDER BY b.title", array($USER->get('id')), $offset, $limit))
|| ($result = array());
foreach ($result as &$r) {
if (!$r->locked) {
$r->deleteform = ArtefactTypeBlog::delete_form($r->id);
}
}
$count = (int)get_field('artefact', 'COUNT(*)', 'owner', $USER->get('id'), 'artefacttype', 'blog');
return array($count, $result);
......@@ -384,6 +390,26 @@ class ArtefactTypeBlog extends ArtefactType {
AND bp.published = 1", array($this->get('id')));
}
public static function delete_form($id) {
global $THEME;
return pieform(array(
'name' => 'delete_' . $id,
'successcallback' => 'delete_blog_submit',
'renderer' => 'oneline',
'elements' => array(
'delete' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'image',
'src' => $THEME->get_url('images/icon_close.gif'),
'elementtitle' => get_string('delete', 'artefact.blog'),
'confirm' => get_string('deleteblog?', 'artefact.blog'),
),
),
));
}
}
/**
......
<script type="text/javascript">
function confirmdelete(id) {
if(confirm("{str tag=deleteblog? section=artefact.blog}")) {
window.location = "{$WWWROOT}artefact/blog/index.php?delete=" + id + '&sesskey=' + config.sesskey;
}
}
</script>
{foreach from=$blogs->data item=blog}
<tr class="{cycle name=rows values='r0,r1'}">
<td>
......@@ -18,7 +11,7 @@
<span class="s dull">{str tag=submittedforassessment section=view}</span>
{else}
<a href="{$WWWROOT}artefact/blog/settings/?id={$blog->id}" title="{str tag=settings}"><img src="{theme_url filename='images/manage.gif'}" alt="{str tag=settings}"></a>
<a href="#" onClick="confirmdelete({$blog->id});" title="{str tag=delete}"><img src="{theme_url filename='images/icon_close.gif'}" alt="{str tag=delete}"></a>
{$blog->deleteform|safe}
{/if}
</td>
</tr>
......
......@@ -65,6 +65,8 @@ td a.btn-add{
#postlist th.controls span.btn-big-del {
padding-bottom: 6px;
}
#bloglist td.buttonscell form,
#bloglist td.buttonscell form div,
#postlist th form,
#postlist th form div {
display: inline;
......
Markdown is supported
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