Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 685

Approve / Deny Apply Buttons

$
0
0
I know that most websites do not utilize this, but I have seen a few postings, and wanted to share some custom code I put into my website. It took me quite a bit of time and trial and error to get this to work properly.

My site has multiple groups across several games, and we use applications to screen new members that come into our community. This is common among online gaming. What I have done is created two buttons that are displayed on these application postings and can quickly put applicants into proper member groups.

[Image: ApproveDeny.jpg]



Getting Started
You will need to have the PHP and Template Conditionals plugin for this to work. I use Nickman's Form Manager for our application forms, but that is an optional plugin, as there are no edits done to that plugin.

Required Plugins:
PHP and Template Conditionals

Optional Plugins:
Form Manager

You will also need to make sure that you are already logged into the Admin CP prior to clicking the buttons. Should you not be logged in prior to it, when you click the button, it will prompt you to log into the Admin CP, and stop the button before it can process through the code.

Should you want to give others this access, you will need to make sure that they have admin access also. What I have done is limited those that can use these buttons to only being allowed to edit users.



The Edits
The template edits will need to be done in postbit and postbit_classic. Both templates will get the same edits. You will want to make your edits after the line below:

Code:
{$post['message']}

Depending on where you want the buttons, you could place it before the message, but it is recommended to be after.



Example Code
Below is an example of the code for one of our sections. There are 2 edits that would need to change, if you would want to utilize this for other forum sections or member groups.

Code:
<if $usergroup['gid'] == 2 and $forum['fid'] == 16 and $post['pid'] == $thread['firstpost'] and $thread['closed'] == 0 then>
<!--- Elder Scrolls Online Approve --->
<div class="appbutton">
<if $mybb->user['usergroup'] == 4 or $mybb->user['usergroup'] == 43 then>
<div class="float_left"><form action="admin/index.php?module=user-users&amp;action=edit&amp;uid={$post['uid']}" method="post" enctype="multipart/form-data" target="_blank">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="username" value="{$post['username']}" />
<input type="hidden" name="email" value="{$post['email']}" />
<input type="hidden" name="displaygroup" value="0" />
<input type="hidden" name="postcount" value="{$post['postnum']}" />
<input type="hidden" name="usergroup" value="16" />
<input type="hidden" name="invisible" value="0">
<input type="hidden" checked="checked" value="1" name="allownotices">
<input type="hidden" checked="checked" value="1" name="receivepms">
<input type="hidden" checked="checked" value="1" name="pmnotice">
<input type="hidden" checked="checked" value="1" name="showsigs">
<input type="hidden" checked="checked" value="1" name="showavatars">
<input type="hidden" checked="checked" value="1" name="showquickreply">
<input type="submit" value="Approve" class="approveapp" />
</form></div>

<div class="float_right">
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
<input type="hidden" name="tid" value="{$thread['tid']}" />
<input type="hidden" name="action" value="openclosethread" />
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="submit" value="Denied" class="declineapp" />
</form></div>
</if>



Understanding the Code
I'm going to break down portions of the code and explain into more detail how they work and why.

Code:
<if $usergroup['gid'] == 2 and $forum['fid'] == 16 and $post['pid'] == $thread['firstpost'] and $thread['closed'] == 0 then>

This runs through multiple checks to determine if the Approve / Deny button should be displayed. It checks that the person posting is in the usergroup 2, the defaulted registered group. Then it checks that the post is in the Forum ID of 16, in the case of my website, Elder Scrolls Online Applications section. This will make sure that the buttons do not get placed onto threads of other forum sections.

Then it checks that it is the first posting, this way that the Approve / Deny button does not get placed onto other posts if you are having a discussion with the applicant. Lastly, it checks that the thread is not closed. Presumably, if a thread is locked, the applicant has been denied or approved, and the thread was locked after approval.


Code:
<if $mybb->user['usergroup'] == 4 or $mybb->user['usergroup'] == 43 then>

This one is simple enough, it sets who will see the button. In this case, myself as admin in group 4, and our Elder Scrolls Leader in group 43.


Code:
<form action="admin/index.php?module=user-users&amp;action=edit&amp;uid={$post['uid']}" method="post" enctype="multipart/form-data" target="_blank">

This creates the link for the button, that will edit the user of the posting. Since the code checks that this is only displayed for those in group 2 and the first post of a thread, it will edit the applicant.


Code:
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="hidden" name="username" value="{$post['username']}" />
<input type="hidden" name="email" value="{$post['email']}" />
<input type="hidden" name="displaygroup" value="0" />
<input type="hidden" name="postcount" value="{$post['postnum']}" />
<input type="hidden" name="usergroup" value="16" />
<input type="hidden" name="invisible" value="0">
<input type="hidden" checked="checked" value="1" name="allownotices">
<input type="hidden" checked="checked" value="1" name="receivepms">
<input type="hidden" checked="checked" value="1" name="pmnotice">
<input type="hidden" checked="checked" value="1" name="showsigs">
<input type="hidden" checked="checked" value="1" name="showavatars">
<input type="hidden" checked="checked" value="1" name="showquickreply">
<input type="submit" value="Approve" class="approveapp" />

This portion of the code was what caused most of the issues. When editing an user through this button, if certain information is in there, it wants to fill in blanks for information. For example, the second line of this portion prompts for the email address. An error that I received while creating this was that it wanted to edit the user, but said a valid email was needed. What was happening was that when I pressed the button, it put in a blank value for the email.

Another issue was that certain boxes were being unchecked, that are typically checked. This is why the lower portion sets certain values to "1", to be checked. These would cause avatars, signatures, and quick reply boxes to be hidden, as example. As a result, the overall theme, and layout of forum pages would not appear correct, and would look like a mess without having those set.

The important portion of this code is the 6th line. In the case of this code, it is placing the user into the member group 16. In the case of my site, Elder Scrolls Online member group.

Code:
<form action="{$mybb->settings['bburl']}/moderation.php" method="post">
<input type="hidden" name="tid" value="{$thread['tid']}" />
<input type="hidden" name="action" value="openclosethread" />
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<input type="submit" value="Denied" class="declineapp" />
</form>

This final portion of the code is for the denied button. This will automatically lock the thread. Going back to the first line, once denied and the post is locked, the Approve / Deny buttons will not be visible.

Viewing all articles
Browse latest Browse all 685

Trending Articles