MyBB Community Forums

Full Version: [ Tutorial ] [ 1.6.x ] Solved Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This script is a little more complex than the UserGroup Legend one I created (if they allow it to go in the tutorials). In this script, there will be some basic editing you'll have to do, because I don't use statements like $mybb->settings['bburl']. Again, if anyone could help make this into a plugin, that'd be great.


REMINDER!
Backup global.php before doing anything.


What is it?
The script is one that allows you to "Solve" a thread for a specific forum (or more if you specify more), locks the thread, moves it to another forum, and adds a post to the thread.

How to Customize
There are lots of things going on here you can customize.
First, you need to have a Solved prefix, so if you don't have one, make it, and replace the prefix # anywhere it's called.
$prefix != '6'

You can add more fid's for the script to check by adding:
$fid != or == 'x'

You can also change the fid to which the Solved threads are moved to.
`fid` = '139'

Then, for the newly added post, you change change the User ID that's used to make the post.
1,

And the message:
'Thread locked.
			If the problem persists, or a new one occurs, feel free to make a new thread.'

So, let's begin.
Make a new file and name it solved.php
Insert the following code into the file.
<?php

define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

$tid = $_GET['tid'];
$threads = $db->query("SELECT * FROM ".TABLE_PREFIX."threads WHERE `tid` = '".$tid."'");
$threads_result = $db->fetch_array($threads);
$prefix = $threads_result['prefix'];
$firstpost = $threads_result['firstpost'];
$username = $mybb->user['username'];
$subject = $threads_result['subject'];
$uid = $threads_result['uid'];
$fid = $threads_result['fid'];
$pid = $threads_result['firstpost'];
$url = "{$mybb->settings['bburl']}/showthread.php?tid=" . $tid;
$title = "JamminGames - Solve Threads";

if($prefix == '6') {
	$message = "This thread has been solved.";
} else if($fid != '39') {
	$message = "Can't solve the thread, wrong forum.";
} else {
	if($prefix != '6' && $fid == '39') {
		if($mybb->user['usergroup'] == '3' || $mybb->user['usergroup'] == '4' || $mybb->user['usergroup'] == '6' || $mybb->user['uid'] == $uid) {
			require_once MYBB_ROOT."inc/datahandlers/post.php";
			$posthandler = new PostDataHandler("insert");

			mt_srand ((double) microtime() * 1000000);
			$posthash = md5($mybb->user['uid'].mt_rand());
			
			$post = array(
				"tid" => $tid,
				"replyto" => $firstpost,
				"fid" => $fid,
				"subject" => $subject,
				"icon" => 0,
				"uid" => $uid,
				"username" => $username,
				"message" => "Thread locked.
If the problem persists, or a new one occurs, feel free to make a new thread.",
				"ipaddress" => get_ip(),
				"posthash" => $posthash
			);

			$post['options'] = array(
				"signature" => 1
			); 
			$posthandler->set_data($post);
			$valid_post = $posthandler->validate_post(); 
			$posthandler->insert_post(); 
			
			$update = array("prefix" => 6, "closed" => 1);
			$db->update_query("threads", $update, "tid = '" . intval($tid) . "'");
			require_once MYBB_ROOT."inc/class_moderation.php";
			$moderation = new Moderation;
			$moderation->move_thread($tid, "139", "move");
			
			$message = "Your <a href='{$mybb->settings['bburl']}/showthread.php?tid=" . $tid . "'>thread</a> has been marked as solved.<br />
				<a href='{$mybb->settings['bburl']}/showthread.php?tid=" . $tid . "'>Return to the thread</a>";
		} else {
			$message = "You have no permission here.";
		}
	}
}
redirect($url, $message);
?>

Next, open global.php and enter this at the very bottom. Change the links for your site:
// Solve a Topic
$tid = $_GET['tid'];
$threads = $db->query("SELECT * FROM ".TABLE_PREFIX."threads WHERE `tid` = '$tid'");
$threads_result = $db->fetch_array($threads);
$fid = $threads_result['fid'];
$uid = $threads_result['uid'];
$prefix = $threads_result['prefix'];
if($mybb->user['usergroup'] == '3' || $mybb->user['usergroup'] == '4' || $mybb->user['usergroup'] == '6' || $uid == $mybb->user['uid']) {
	if($prefix == '6') {
		$solved = "This Thread is Solved";
	} elseif ($prefix != '6' && $fid == '39') {
		$solved = "<a href='{$mybb->settings['bburl']}/solved.php?tid=$tid'>Solve this Thread</a>";
	} elseif ($fid != '39') {
		$solved = "Can't Solve a Thread Here";
	}
} else {
	$solved = "No Permission";
}

Then, goto Admin CP -> Templates & Styles -> Templates -> Your Theme -> (Whatever template you want). For me, I put it to the left of "Threaded Mode", which is the Showthread -> showthread template
Add this wherever you want it:
{$solved}

Then, the script should work and Solve threads for certain forums, lock them, and move them to a certain forum.

If you have any questions or comments, post them below.
Massive edits have been made to the original thread for the script.
Please, if you are currently using code before this post, update it.
Could just use MySupport or custom moderator tools/thread prefixes.

Good guide though.
I created this before that came out.