Topic: Instead of deleting a topic, how about closing it?

Hi,

I'm wondering if it would be difficult for one to be able (permissions based) to close his own post.
Instead of having the ability to delete a whole topic, the user would only have the ability to close it.

Any thoughts?

I've tried to replace the sql query in functions.php but it didn't work. What I did:

// Delete the topic and any redirect topics
//$db->query('DELETE FROM '.$db->prefix.'topics WHERE id='.$topic_id.' OR moved_to='.$topic_id) or error('Unable to delete topic', __FILE__, __LINE__, $db->error());
  $db->query('UPDATE '.$db->prefix.'topics SET closed=1 WHERE id='.$topic_id) or error('Unable to close topic', __FILE__, __LINE__, $db->error());

I've copied that query from moderate.php... tongue

It indeed closes the topic but when clicking on it from viewforum.php I only get top_navlinks and bottom_navlinks with nothing between them... big_smile
Quite a programmer hey?

Anyone willing to help? I'll be paying with a lot of "thank you's". smile

2 (edited by fmimoso 2007-10-15 18:08)

Re: Instead of deleting a topic, how about closing it?

Hmmm...

I forgot to comment the rest of the delete_topic function. So it was closing the topic and deleting any posts in it.
It's working now!

Try it!

1. Open include/functions.php
2. Find line 378

Before:

//
// Delete a topic and all of it's posts
//
function delete_topic($topic_id)
{
    global $db;

    // Delete the topic and any redirect topics
    $db->query('DELETE FROM '.$db->prefix.'topics WHERE id='.$topic_id.' OR moved_to='.$topic_id) or error('Unable to delete topic', __FILE__, __LINE__, $db->error());

    // Create a list of the post ID's in this topic
    $post_ids = '';
    $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
    while ($row = $db->fetch_row($result))
        $post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];

    // Make sure we have a list of post ID's
    if ($post_ids != '')
    {
        strip_search_index($post_ids);

        // Delete posts in topic
        $db->query('DELETE FROM '.$db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
    }

    // Delete any subscriptions for this topic
    $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id='.$topic_id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
}

After:

//
// Delete a topic and all of it's posts
//
function delete_topic($topic_id)
{
    global $db;

    // Delete the topic and any redirect topics
//    $db->query('DELETE FROM '.$db->prefix.'topics WHERE id='.$topic_id.' OR moved_to='.$topic_id) or error('Unable to delete topic', __FILE__, __LINE__, $db->error());
    $db->query('UPDATE '.$db->prefix.'topics SET closed=1 WHERE id='.$topic_id) or error('Unable to close topic', __FILE__, __LINE__, $db->error());

/*
    // Create a list of the post ID's in this topic
    $post_ids = '';
    $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
    while ($row = $db->fetch_row($result))
        $post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];

    // Make sure we have a list of post ID's
    if ($post_ids != '')
    {
        strip_search_index($post_ids);

        // Delete posts in topic
        $db->query('DELETE FROM '.$db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
    }

    // Delete any subscriptions for this topic
    $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id='.$topic_id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
*/
}

Don't forget to replace "Delete" with "Close" where needed (language files).

Downside: you no longer can delete topics! tongue