View Full Version : Plugin Backend
KGodel
06-24-2014, 09:38 PM
Hey everyone. So lately I've been searching for someone to do this for me but I figure if I learned it myself it'd be much more helpful to me in the future. I run a gaming clan, and we have a roster. You can view it here: http://www.zealotgaming.com/forum/pages.php?pageid=15
Obviously, you can see a few things. The default page lists all our staff. That is very easy, and not really the part I need help with. The help begins with the games list you see at the side. When you click a game, it lists all users who have that Game listed as their Main Game in a profile field, and lists other info, such as their rank, In-Game contact (which is another profile field) and join date/last active. The games are also themselves divided into categories.
Our code is relatively simple. We keep a manual array of info that keeps these together you can see below:
// Define Games and Lists //
$gameslist = array();
//SETUP $gamelist[] = array("Game Name","urlshortcode","Name of In-Game Name or Account", "field# for that profile field");
$gameslist[] = array("Battlefield 4 (PS4)", "bf4ps4", "PlayStation ID", "field7");
$gameslist[] = array("Counter Strike: Global Offensive (EU)", "csgoeu", "Steam ID", "field8");
$gameslist[] = array("Counter Strike: Global Offensive (NA)", "csgona", "Steam ID", "field8");
$gameslist[] = array("Elder Scrolls Online (NA)", "esona", "Main Character", "field45");
$gameslist[] = array("League of Legends (EUNE)", "loleune", "Summoner Name", "field12");
$gameslist[] = array("League of Legends (EUW)", "loleuw", "Summoner Name", "field31");
$gameslist[] = array("League of Legends (NA)", "lolna", "Summoner Name", "field32");
$gameslist[] = array("League of Legends (OCE)", "loloce", "Summoner Name", "field47");
$gameslist[] = array("Minecraft", "mc", "Username", "field14");
$gameslist[] = array("Smite (EU)", "smiteeu", "Smite Account", "field22");
$gameslist[] = array("Smite (NA)", "smitena", "Smite Account", "field22");
$gameslist[] = array("Titanfall", "tfall", "Origin ID", "field29");
$gameslist[] = array("WildStar (EU)", "wseu", "Main Character", "field48");
$gameslist[] = array("WildStar (NA)", "wsna", "Main Character", "field48");
$gameslist[] = array("World of Tanks (EU)", "woteu", "WarGaming.NET ID", "field46");
$gameslist[] = array("Other Game", "other", "", "");
// Game Type Categories
$gamecats = array();
// ADD the # of the game in the list above (starting from 0) to the appropriate category array number list.
$gamecats[] = array("Divisions",array(4,5,6));
$gamecats[] = array("Guilds",array());
$gamecats[] = array("Gaming Groups",array());
$gamecats[] = array("Divisions in Development",array(0,1,2,3,7,8,9,10,11,12,13,14));
$gamecats[] = array("Miscellaneous",array(15));
This gets tedious to keep track of manually, and my admins with no programming experience can barely understand what is happening.
The listing of users is very easy, and I do not need any help with that. What I would like to add is a manager in the admin panel where you could save the information listed above to a table such as PREFIX.games. I imagine having several drop down boxes. A mockup is below:
https://vborg.vbsupport.ru/external/2014/06/18.png
I'd then Like a list of games that includes these rows in the table with a [ ] Remove checkbox.
I do not know how to add this to the admin panel and would love guidance on how to begin doing this. The sorting would go by Game Status (the second array in my php code) then Alphabetical. This would go a long way in helping my staff edit this list themselves. Any help would be appreciated.
Skype: j.c.will my be better to work personally with me.
ForceHSS
06-24-2014, 10:02 PM
Please post this to the correct forum/section
ozzy47
06-24-2014, 10:08 PM
Please post this to the correct forum/section
Why not point the poster to the correct section?
KGodel
06-24-2014, 10:08 PM
This seemed like the correct section? For general help. Isn't this help? o.O
Forum description: "How do I do this in vBulletin?"
I am asking how do I add a backed plugin in vBulletin. So I am in the correct forum.
But thank you anyhow. Your comment was clearly insightful and helpful.
ForceHSS
06-24-2014, 10:26 PM
Why not point the poster to the correct section?
because I was busy only had time to write a quick message
--------------- Added 25 Jun 2014 at 00:28 ---------------
This seemed like the correct section? For general help. Isn't this help? o.O
Forum description: "How do I do this in vBulletin?"
I am asking how do I add a backed plugin in vBulletin. So I am in the correct forum.
But thank you anyhow. Your comment was clearly insightful and helpful.
If you need to ask any questions about a plugin you need to post in the topic for the plugin as I did point out in one of your other posts. If it is a plugin you want made then either in unpaid or paid section (depends how much coding is needed)
KGodel
06-24-2014, 11:08 PM
I am not looking for someone to create this forum me. It is not an existing plugin. I am asking on how to create part of a plguin, which qualifies as "how do you do this" in vbulletin. Please read my posts and understand what I am asking before you make claims about my goals or purposes.
I would respectfully appreciate it if you would leave the thread alone unless you are here to offer help with the question I have asked.
ForceHSS
06-24-2014, 11:27 PM
Asking how to create part of a plugin is still asking for help with someone doing coding for you either free or paid and really no need to be rude I am trying to help
ozzy47
06-25-2014, 12:00 AM
because I was busy only had time to write a quick message
--------------- Added 25 Jun 2014 at 00:28 ---------------
Then perhaps it would be wise to not answer a post, if you don't have the time to help correctly. I know you mean well, but the way you go about if sometimes leave a lot of open ended nonsense, which leads to quite a bit of back and forth nonsense. :)
ForceHSS
06-25-2014, 12:30 AM
Yes sometimes I do its just the way I am but I do like and try to help even if it takes a while to get to the point
KGodel
06-25-2014, 01:29 AM
I am not asking anyone to code for me, I am asking for the first step of how to go about doing the back end. Anyone in this forum who asks questions about code could be said the same thing "you are asking about code, go pay someone". I am hoping someone can point me in the right direction to design a backend myself.
--------------- Added 1403673493 at 1403673493 ---------------
So far, I've gotten this far:
<?php
// Rosters
// by DrMath
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('style');
$specialtemplates = array('products');
// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/adminfunctions_template.php');
$this_script = 'rosters';
$rpm_ver = 1.0;
$rpm_mouseover_fontcolor = '#D04850';
// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminforums'))
{
print_cp_no_permission();
}
print_cp_header();
// Get Profile Fields //
$sql = "SELECT profilefieldid FROM " . TABLE_PREFIX . "profilefield";
$result = $db->query_read($sql);
$fields = array();
while( $a = mysql_fetch_array($result) ) {
$fields[] = "field" . $a[0];
}
// Get Main Games //
$sql = "SELECT profilefieldid, data FROM " . TABLE_PREFIX . "profilefield WHERE profilefieldid = 5";
$result = $db->query_read($sql);
$gamesbase = mysql_fetch_array($result);
$gamesbase = unserialize($gamesbase[1]);
foreach ($gamesbase as $game) {
$games[] = $game;
}
// Game Status //
$gamestatuses = array('Divisions', 'Guilds', 'Divisions in Development', 'Miscellaneous');
/////////////////////// front page
if ( empty($_REQUEST['do']) ) {
print_form_header($this_script, 'add');
print_table_header('Add Game');
print_select_row('Main Game', 'game', $games );
print_input_row('Abbreviation', 'abbrev');
print_input_row('Account Name', 'acctname');
print_select_row('Account Profile Field', 'proffield', $fields);
print_select_row('Game Status', 'status', $gamestatuses);
print_submit_row('Submit New Game');
}
////////////////////// get current games
$sql = "SELECT * FROM " . TABLE_PREFIX . "gamelist";
$result = $db->query_read($sql);
print_form_header($this_script, 'remove');
print_table_header('Current Games in Roster',6);
echo "<tr><th>Game</th><th>Abbreviation</th><th>In-Game Name</th><th>Profile Field</th><th>Status</th><th>Delete?</th></tr>";
while ($game = mysql_fetch_array($result)) {
echo "<tr>
<td>$game[1]</td>
<td>$game[2]</td>
<td>$game[3]</td>
<td>$game[4]</td>
<td>$game[5]</td>
<td stlye='text-align:center;'><input type='checkbox' name='delete' value='$game[0]'></td>
</tr>";
}
print_table_footer(6,'','',0);
/////////////////////// add
if ( $_REQUEST['do'] == 'add' ) {
if ( empty($_REQUEST['game']) OR empty($_REQUEST['abbrev']) OR empty($_REQUEST['acctname']) OR empty($_REQUEST['proffield']) OR empty($_REQUEST['status'])) { rpm_print_stop_back('Please be sure every field is filled out before submitting.'); }
$game = $_REQUEST['game'];
$abbrev = $_REQUEST['abbrev'];
$acctname = $_REQUEST['acctname'];
$proffield = $_REQUEST['proffield'];
$status = $_REQUEST['status'];
$sql = "INSERT INTO TABLE " . TABLE_PREFIX . "gamelist (gamename, abbreviation, ingamename, profilefield, status)
VALUES ($game, $abbrev, $acctname, $proffield, $status)";
$db->query_write($sql);
if ($db->affected_rows() != 0) {echo "Game Added!";} else { $db->error();}
}
print_cp_footer();
?>
So now that these are populated how I'd like I can created an "add" post and run the query to add it to a new table yea? Now can anyone tell me how to add it to the menu on the left side and create an administrator "canadmin" property?
Also, for some reason my "add" code is not working properly. I think the DB writing isn't happening.
There are a few things wrong:
- You are using $_REQUEST, please stick to $_POST or $_GET. Depending on which one you use.
- You don't wrap your variables in single quotes, will not work without that.
- You don't escape your variables, SQL injection will be possible.
- Your INSERT query contained "INSERT INTO TABLE", that's not valid.
In case you use $_POST, you can do something like:
/////////////////////// add
if ( $_POST['do'] == 'add' ) {
if ( empty($_POST['game']) OR empty($_POST['abbrev']) OR empty($_POST['acctname']) OR empty($_POST['proffield']) OR empty($_POST['status'])) { rpm_print_stop_back('Please be sure every field is filled out before submitting.'); }
$sql = "INSERT INTO " . TABLE_PREFIX . "gamelist (gamename, abbreviation, ingamename, profilefield, status)
VALUES ('" . $db->escape_string($_POST['game']) . "', '" . $db->escape_string($_POST['abbrev']) . "', '" . $db->escape_string($_POST['acctname']) . "', '" . $db->escape_string($_POST['proffield']) . "', '" . $db->escape_string($_POST['status']) . "')";
$db->query_write($sql);
if ($db->affected_rows() != 0) {echo "Game Added!";} else { $db->error();}
}
In case of $_GET:
<?php
/////////////////////// add
if ( $_GET['do'] == 'add' ) {
if ( empty($_GET['game']) OR empty($_GET['abbrev']) OR empty($_GET['acctname']) OR empty($_GET['proffield']) OR empty($_GET['status'])) { rpm_print_stop_back('Please be sure every field is filled out before submitting.'); }
$sql = "INSERT INTO " . TABLE_PREFIX . "gamelist (gamename, abbreviation, ingamename, profilefield, status)
VALUES ('" . $db->escape_string($_GET['game']) . "', '" . $db->escape_string($_GET['abbrev']) . "', '" . $db->escape_string($_GET['acctname']) . "', '" . $db->escape_string($_GET['proffield']) . "', '" . $db->escape_string($_GET['status']) . "')";
$db->query_write($sql);
if ($db->affected_rows() != 0) {echo "Game Added!";} else { $db->error();}
}
KGodel
06-25-2014, 06:16 PM
Hey Dave! I made your changes and the SQL write still isn't working. I get a blank screen when I click submit and nothing changes in the table. No error is sent to my email inbox either.
Add the following above the query_write execution:
echo $sql;
Then just try to add another game again and copy the SQL query that's being displayed on the page, then manually execute it in something like PHPMyAdmin, see if this works and if it's showing an error.
KGodel
06-25-2014, 08:00 PM
It isn't even showing an SQL query.
Lynne
06-25-2014, 09:34 PM
If it isn't even showing the query, then try adding something like this above the second if statement:
echo $_GET['game'];
(actually, try echoing all three of your $_GET variables)
KGodel
06-25-2014, 10:12 PM
I actually had both parts working (adding and removing). The adding part worked after I manually added the first row to the database. I tried the remove function and removed the first row, and now it won't add it again. Does the first key always have to be 1? Do I have to update keys?
Edit: Seemed to be an error with the insert query. All fixed! Now could someone tell me how to add it to the menu in the ACP and create an admin permission for it?
Edit: Figured that out too. Now I will link it to the main result. Thank you to the few people who helped me in this thread with genuine advice!
<?php
// Rosters
// by DrMath
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('style');
$specialtemplates = array('products');
// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/adminfunctions_template.php');
$this_script = 'rosters';
$rpm_ver = 1.0;
$rpm_mouseover_fontcolor = '#D04850';
// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminusers'))
{
print_cp_no_permission();
}
print_cp_header();
echo "<div class='pagetitle'>Edit Clan Rosters</div>";
// Get Profile Fields //
$sql = "SELECT profilefieldid FROM " . TABLE_PREFIX . "profilefield";
$result = $db->query_read_slave($sql);
$fields = array();
$fields[] = "";
while( $a = mysql_fetch_array($result) ) {
$fields[] = "field" . $a[0];
}
// Get Main Games //
$sql = "SELECT profilefieldid, data FROM " . TABLE_PREFIX . "profilefield WHERE profilefieldid = 5";
$result = $db->query_read_slave($sql);
$gamesbase = mysql_fetch_array($result);
$gamesbase = unserialize($gamesbase[1]);
$games = array();
$games[] = "";
foreach ($gamesbase as $game) {
$games[] = $game;
}
// Game Status //
$gamestatuses = array("","Divisions", "Guilds", "Divisions in Development", "Miscellaneous");
/////////////////////// front page
if ( empty($_POST['do']) ) {
print_form_header($this_script, 'add');
print_table_header('Add Game');
print_select_row('Main Game', 'game', $games);
print_input_row('Abbreviation', 'abbrev');
print_input_row('Account Name', 'acctname');
print_select_row('Account Profile Field', 'proffield', $fields);
print_select_row('Game Status', 'status', $gamestatuses);
print_submit_row('Add Game');
////////////////////// get current games
$sql = "SELECT * FROM " . TABLE_PREFIX . "gamelist ORDER BY gamename ASC";
$result = $db->query_read_slave($sql);
print_form_header($this_script, 'remove');
print_table_header('Current Games in Roster',6);
echo "<tr><th>Game</th><th>Abbreviation</th><th>In-Game Name</th><th>Profile Field</th><th>Status</th><th>Delete?</th></tr>";
$i = 0;
while ($game = mysql_fetch_array($result)) {
if ($i & 1) {$added = "class='alt1' style='text-align:center;'";} else {$added = "class='alt2' style='text-align:center;'";}
echo "<tr>
<td $added>$game[1]</td>
<td $added>$game[2]</td>
<td $added>$game[3]</td>
<td $added>$game[4]</td>
<td $added>$game[5]</td>
<td $added><input type='checkbox' name='delete[]' value='$game[0]'></td>
</tr>";
$i ++;
}
print_submit_row('Remove Selected',"Reset",6);
}
/////////////////////// add
if ( $_POST['do'] == 'add' ) {
if ( empty($_POST['game']) OR empty($_POST['abbrev']) OR empty($_POST['status']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
$vbulletin->input->clean_array_gpc('p', array(
'game' => TYPE_UNIT,
'abbrev' => TYPE_STR,
'acctname' => TYPE_STR,
'proffield' => TYPE_UNIT,
'status' => TYPE_UNIT
));
$pgame = $db->escape_string($games[$vbulletin->GPC['game']]);
$pabr = $db->escape_string($vbulletin->GPC['abbrev']);
$pacctname = $db->escape_string($vbulletin->GPC['acctname']);
$pfield = $db->escape_string($fields[$vbulletin->GPC['proffield']]);
$pstatus = $db->escape_string($gamestatuses[$vbulletin->GPC['status']]);
$sql = "INSERT INTO " . TABLE_PREFIX . "gamelist (gamename, abbreviation, ingamename, profilefield, status) VALUES ('$pgame', '$pabr', '$pacctname', '$pfield', '$pstatus')";
$db->query_write($sql);
define('CP_REDIRECT', 'rosters.php');
print_stop_message('roster_game_added');
}
/////////////////////// remove
if ( $_POST['do'] == 'remove' ) {
$vbulletin->input->clean_array_gpc('p', array(
'delete' => TYPE_ARRAY));
foreach ($vbulletin->GPC['delete'] as $deleted) {
if(isset($deleted)){
$removed[] = (int)$deleted;
}
}
foreach ($removed as $delete) {
$sql = "DELETE FROM " . TABLE_PREFIX . "gamelist WHERE gameid = $delete";
$db->query_write($sql);
}
define('CP_REDIRECT', 'rosters.php');
print_stop_message('roster_game_removed');
}
print_cp_footer();
?>
--------------- Added 1403741863 at 1403741863 ---------------
Correction, it is letting me add SOME games, but not others. I do not know why.
--------------- Added 1403743899 at 1403743899 ---------------
The error occurs whenever I do not change one of the drop down menus. It seems like it isn't being sent as if its selected, so it is causing an error.
EDIT: To fix I simply added a blank option at the start of each menu. Worked like a charm.
Edit: Added an image to see it working. ^^
https://vborg.vbsupport.ru/external/2014/06/17.png
TheLastSuperman
06-26-2014, 07:30 PM
Awesome KGodel!!!! I received your pm and came to check - glad to see you kept on tinkering until you figured it out with the help of a few others of course so props to them as well but I'm thrilled for you :D.
Now what's next? Remember that sometimes banging your head against a brick walls helps you remember the issue and resolution afterwards and also prepares you for the next step on your forum (typically) so find something else you want done and have at it!
:cool:
KGodel
06-26-2014, 07:33 PM
Well, instead of using a page-plugin, I like to move the roster to is own page and maybe even release this as a mod to the community (eventually). This was the biggest thing we wanted to do so I don't know what else I'll do now, I'm just enjoy this (I have it open in a tab just to look at it, lol).
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.