MyBB Community Forums

Full Version: Add page in acp
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm writing a plugin for restoring posts from a deleted user to an existing user or a newly created user, but the problem is, I need to have the page in the ACP and I'm not sure how I would do that. Is there specific code I have to add, or what?

I hope I won't have to add another file to the acp, but if I have to I will.
Admin CP pages are boring to code, reaaaalllyyyyyyyyy boring.. (in my opinion)
I suggest you to take a look at existing plugins so you can understand exactly how things work.
There's no "specific code" you must put and voilá it's there, the page is showing everything you want. there are functions you call which output the data you want
Plugin File:

Hooks:
$plugins->add_hook("admin_tools_menu", "FNAME_menu");
$plugins->add_hook("admin_load", "FNAME_admin");
$plugins->add_hook("admin_tools_action_handler", "FNAME_action_handler");

Functions:
function FNAME_menu(&$sub_menu)
{
	global $mybb;
	
	end($sub_menu);
	$key = (key($sub_menu))+10;
		
	if(!$key)
	{
		$key = '160';
	}
		
	$sub_menu[$key] = array('id' => 'FNAME', 'title' => 'FNAME', 'link' => "index.php?module=tools/FNAME");	
}

function FNAME_action_handler(&$action)
{
	$action['FNAME'] = array('active' => 'FNAME', 'file' => 'FNAME.php');
}

function FNAME_admin()
{
	global $page, $mybb;
	if($page->active_action != "FNAME")
	{
		return;
	}
	$page->add_breadcrumb_item("My PluginName");
}

ACP PAGE:
Create a PHP Page with as name 'FNAME' ( the same as your pluginfile ! ). After putting all your code in it; upload it into ./admin/modules/tools/ . Also in your ACP there should be a new link (in the left column) under the tab 'Tools & Maintenance' if your plugin is active;
And take a look at the attached file for more info about an ACP Page.
Thank you Lex. Hopefully when I finish the plugin, it will be very helpful. Smile
Okay, few more questions.

1. How do I update a table such as the posts table using $db->update_query? The wiki isn't much help.
2. Can you explain what you mean by "After putting all your code in it"? What code?
3. For a form, do I *HAVE* to use the crap you had in the example file, or can I just have it just use print "<form stuff here>";?
1.
	/**
	 * Build an update query from an array.
	 *
	 * @param string The table name to perform the query on.
	 * @param array An array of fields and their values.
	 * @param string An optional where clause for the query.
	 * @param string An optional limit clause for the query.
	 * @return resource The query data.
	 */
	function update_query($table, $array, $where="", $limit="", $no_quote=false)

Example:
$update_vars = array('subject' => 'Test Example', 'username' => 'LeX-', 'uid' => '1');
$db->update_query('posts', $update_vars, 'pid=51');

Or check a plugin of me or someone else; i'm sure there's plenty examples of it.


2. Well if you're gonna create an ACP page; you have to add your code to it ? How else would you manage to restore posts of a user etc. ...

3. That aint crap; MyBB has put alot of effort in creating it that way: so i use it that way.
but no you aint have to use it; you can simply echo all the stuff you want
Okay, another 2 questions.

1. What if I want to update something in the db where username is XXX and userid is 1, would I use an array for the where info?

2. How would I pass 2 things from a function? I have it so that there is a function to call the form, then after submission, it calls a check function, then if the username/id fields were filled it would call the update function. I need it to pass 2 variables to the other functions.

Here is the code if you want to see what I'm trying to do.
function rduser_updateuser($rduser,$rdinfo){
	/*the passed vars should end up here somewhere.*/
global $mybb,$db;

$updatevars = array(
					"uid"=>"$rduid"
					);
$wherevars = array(
					"username=$rduser",
					"userid=0"
					);

$db->update_query("posts", $updatevars, $wherevars) or die("Query Failed...");

print "Posts updated correctly!";}

function rduser_check($rduser,$rdinfo){
	/*the passed vars should be here for the check to work.*/
	
	$msgfa = "Username/userid blank, please check that they are filled.";
	
	if($rduser == ''){print $msgfa;}
	else{
		if($rduid == ''){print $msgfa;}
		else{
			rduser_updateuser($rduser,$rdinfo);}
	}
}
			
			
function rduser_form(){
if(isset($_POST['restore'])){
	$rduser = $db->escape_string($mybb->input['rduser']);
$rduid = $db->escape_string($mybb->input['rduid']);
/*somehow this is where i have to have the vars sent to the check function.*/
rduser_check($rduser,$rduid);}
else{
	print '<form method="post" action="">From here you can restore a user\'s posts<br />
Username: <input type="text" name="rduser"> This is the user name you are going to be replacing.<br />
Userid: <input type="text" name="rduid"> This is the ID of the new poster.<br />
<input type="submit" name="restore" value="Restore User"></form>';
	}//end the form
}

Edit:
Also, the pages error in the ACP with the hooks.
Try this:
Upload like its stored in the .zip file;
That works, but there are a few things that are not needed in the ACP page. Mostly the OldID.
If you delete the olduid; how will you know from which user you need to grab the posts ?
I was going to have it set up to that it replaces the UID where the uid is 0 and the username matches what is in the text field. I've tried the query in phpmyadmin, and it works, now I just need to make the mybb plugin work.

I could post the one I made for vB which is where I got the idea.
Pages: 1 2