MyBB Community Forums

Full Version: Help Needed.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Quoted from my post at myBB Mods:

Ryan @ MyBB Mods Wrote:Well, I've changed it completely around from what I was gonna do originally.

I've got the database all set up with a new table called "installs" with the following: username, uid, and tid.

And when someone installs the mod their username, uid, and the tid of the thread is inserted into the table.

I got it all set up and I click install to test it. The information is inserted into the database fine, but, the install doesn't change to an uninstall link.

It's confused me...

Here's the code I used in showthread.php.

// ############################# Install Hack ##################################
// Database Stuff
if ($thread[fid]==2)
{
$installerid = $db->query("SELECT uid FROM installs WHERE tid = $tid and uid = $mybbuser[uid]");
}
// Install Link
if ($thread[fid]==2 && $installerid[uid]!=$mybbuser[uid])
{
$install="( <a href=\"showthread.php?do=install&tid=$tid\">Install This Mod</a> )";
}
else
{
$install="";
}
// Uninstall Link
if ($thread[fid]==2 && $installerid[uid]==$mybbuser[uid])
{
$uninstall="( <a href=\"showthread.php?do=uninstall&tid=$tid\">Uninstall This Mod</a> )";
}
else
{
$uninstall="";
}
// Do Install
if ($_REQUEST["do"] == "install")
{
if ($installerid[userid]!=$mybbuser[uid])
{
$db->query("
INSERT INTO installs
(username,uid,tid)
VALUES
('".addslashes($mybbuser[username])."','".$mybbuser[uid]."','".$tid."')
");

}
eval("\$message = \"".$templates->get("redirect_installed")."\";");
redirect("$settings[bbname] - Mod Installed", $message, "showthread.php?tid=$tid");
}

// Do Un-Install
if ($_REQUEST["do"] == "uninstall")
{
$db->query("
DELETE FROM installs WHERE tid = $tid AND uid = $mybbuser[uid]
");
eval("\$message = \"".$templates->get("redirect_uninstalled")."\";");
redirect("$settings[bbname] - Mod Uninstalled", $message, "showthread.php?tid=$tid");
}
// ####################### End Install Hack ####################################

Anything wrong?

I'm posting this at both places because I need this really badly.
I'll reply to you here, as I haven't fixed the code tags at myBB Mods. I'll probably wait untill RC3 because I'm feeling quite lazy at the moment. Toungue

I've taken a look at your code and think I see the problem. I've taken it and modified it a little, incorporating a few changes which should make it work. I've changed a few other little things too that may make a difference, but shouldn't change anything if not.

Bare in mind that this code is untested, but I believe it should still do what you want it to.

// ############################# Install Hack ##################################

// Database Stuff
if ($thread[fid]==2)
{
	$query = $db->query("SELECT * FROM installs WHERE tid='$tid' AND uid='$mybb[uid]'");
	$installerid = $db->fetch_array($query);
}

// Install Link
if ($thread[fid]==2 && $installerid[uid]!=$mybb[uid])
{
	$install="( <a href=\"showthread.php?do=install&tid=$tid\">Install This Mod</a> )";
}
else
{
	$install="";
}

// Uninstall Link
if ($thread[fid]==2 && $installerid[uid]==$mybb[uid])
{
	$uninstall="( <a href=\"showthread.php?do=uninstall&tid=$tid\">Uninstall This Mod</a> )";
}
else
{
	$uninstall="";
}

// Do Install
if ($_REQUEST["do"] == "install")
{
    if ($installerid[uid]!=$mybb[uid])
    {
		$db->query("
		INSERT INTO installs
		(username,uid,tid)
		VALUES
		('".addslashes($mybb[username])."','".$mybb[uid]."','".$tid."')
		");

    }
	eval("\$message = \"".$templates->get("redirect_installed")."\";");
	redirect("$settings[bbname] - Mod Installed", $message, "showthread.php?tid=$tid");
}

// Do Un-Install
if ($_REQUEST["do"] == "uninstall")
{
	$db->query("DELETE FROM installs WHERE tid='$tid' AND uid='$mybb[uid]'");
	eval("\$message = \"".$templates->get("redirect_uninstalled")."\";");
	redirect("$settings[bbname] - Mod Uninstalled", $message, "showthread.php?tid=$tid");
}

// ####################### End Install Hack ####################################

Something small I noticed in the code, is that you have no way of preventing guest users from installing and uninstalling mods, so to add this, you may like to place the installation and uninstallation database queries in the following code.

if($mybb[uid] == 0)
{
nopermission();
}
else
{
// Install or uninstall query here
}

Guests have the uid of 0 by default, so the above code will display the "No Permissions" code to anyone with a uid of 0 that tries to install or install a mod. Ie, guests see the error, logged in users don't.

Let me know how you get on.

* Alan Crisp wonders if [php] tags will ever be finished here. Could have been handy in this post. Toungue
Ok, thanks, I'll try it now. ^_^

It worked! Thanks a lot MM!

(And this is why I don't deal with SQL unless I have too) Toungue
Another question, I had to modify it so it would work for multiple forums.

// ############################# Install Hack ##################################
// Prevent Guests from Installing
if($mybb[uid] == 0)
{
nopermission();
}
else
{
// Database Stuff
if ($thread[fid]==7 || $thread[fid]==8 || $thread[fid]==9 || $thread[fid]==10 || $thread[fid]==11 || $thread[fid]==12 || $thread[fid]==13)
{
$query = $db->query("SELECT * FROM installs WHERE tid='$tid' AND uid='$mybb[uid]'");
$installerid = $db->fetch_array($query);
}

// Install Link
if ($thread[fid]==7 || $thread[fid]==8 || $thread[fid]==9 || $thread[fid]==10 || $thread[fid]==11 || $thread[fid]==12 || $thread[fid]==13 && $installerid[uid]!=$mybb[uid])
{
$install="( <a href=\"showthread.php?do=install&tid=$tid\">Install This Mod</a> )";
}
else
{
$install="";
}

// Uninstall Link
if ($thread[fid]==7 || $thread[fid]==8 || $thread[fid]==9 || $thread[fid]==10 || $thread[fid]==11 || $thread[fid]==12 || $thread[fid]==13 && $installerid[uid]==$mybb[uid])
{
$uninstall="( <a href=\"showthread.php?do=uninstall&tid=$tid\">Uninstall This Mod</a> )";
}
else
{
$uninstall="";
}

// Do Install
if ($_REQUEST["do"] == "install")
{
    if ($installerid[uid]!=$mybb[uid])
    {
$db->query("
INSERT INTO installs
(username,uid,tid)
VALUES
('".addslashes($mybb[username])."','".$mybb[uid]."','".$tid."')
");

    }
eval("\$message = \"".$templates->get("redirect_installed")."\";");
redirect("$settings[bbname] - Mod Installed", $message, "showthread.php?tid=$tid");
}

// Do Un-Install
if ($_REQUEST["do"] == "uninstall")
{
$db->query("DELETE FROM installs WHERE tid='$tid' AND uid='$mybb[uid]'");
eval("\$message = \"".$templates->get("redirect_uninstalled")."\";");
redirect("$settings[bbname] - Mod Uninstalled", $message, "showthread.php?tid=$tid");
}
// Prevnt Guests from Installing End Tag
}
// ####################### End Install Hack ####################################

Did I do it right? Cuz it shows both the Install and Uninstall link when it's supposed to show one or the other...
Just a suggestion for you...

Rather than adding each forum to the script, (ie. $thread[fid] == 1 || $thread[fid] == 2), why not just add a setting to each forum for allowing installations/uninstallations of your mods. It would need a new column in the forums table, for example, call it "allow_installations", then you can clean up the script by replacing all the ($thread[fid] == whatever) with if($forum['allow_installations'] == "yes") etc. Smile
Ok, I'll try it.

I guess in turn I did need to use your suggestions, in the thread at MyBB Mods. Toungue
Ok, that worked, however, I'm still having the issue with both links appearing instead of one.

Ahh! I got it working. Big Grin