PDA

View Full Version : Admin CP


Zok
05-12-2007, 06:16 PM
So I'm thinking that an administration control panel is in order for zb3. I want it to be entirely php+mysql based. Some features that I was thinking about having in the cp were:

The ability to link two names and list out all names linked to a UID.

The ability to clean up the database (user_stats is going to get huuuge after a few months of high traffic channels. It's best to clean out unused nicknames from the db).

Maybe also a way to output a configuration file for the bot? Since the bot doesn't have a config file yet, maybe this feature will be added in later versions.

More details on how each feature is to work later.

Zok
05-30-2007, 05:01 PM
I've added the first function to the admin cp (before it was just an empty page). I added a utility that links two nicknames together so that they will be treated as the same nick when statistics are being recorded.

The code was actually quite simple. Here's an outline of what I did:

Get nick0 and nick1 from html form
Check for illegal characters in both
Get the UID tags for both nicknames from nickname association table (UID is a user identification number - Actually the current unix time when the bot recorded your first line of text)
Remove "main" flag from nick1 so that it is no longer a primary nickname
while printing all tables in the database:
{
Check to see if the table has the prefix that indicates it's a dynamically named stats table (in the format: stats_channelname)
Extract all of UID1's data from the table
Add each column of extracted data to a corresponding column in UID0's data
Delete UID1's row from that table (Not from nickname association table!)
}
// At this point all data has been changed in dynamically named tables, now for the constant ones
Extract all of nick1's data from the master stats table
Add it to UID0's data in the master stats table
Delete UID1's entry in master stats
//At this point, all data from nick1 has been added to nick0. Now to make the changes official.
Change UID of nick1 to the UID of nick0 in the nickname association table
//You're done!


Actual code:


<?php
/*
File: mergusers.php
This script merges two users. nick0 is the PRIMARY nickname. nick1 is the nick that will be merged INTO nick0
*/
// include and connect to db handlers
include("../inc.php");
dbconnect();
// if the the data is being submitted...
if(!empty($_GET['submit']))
{
$nick0= $_POST['nick0'];
$nick1 = $_POST['nick1'];
// First check both nicks for illegal characters! Then get both UID's
if ( !preg_match("#^[a-z0-9_`\-]+$#i",$nick0) || !preg_match("#^[a-z0-9_`\-]+$#i",$nick1) ){
print "One or more of your nickname entries contained illegal characters.";
return;
}
// If you're here, the nicks were safe. Get the UID's for them now
$uid0 = mysql_fetch_row(mysql_query("SELECT `uid` from `$users` WHERE `nick`='$nick0'"));
$uid0 = $uid0[0];
$uid1 = mysql_fetch_row(mysql_query("SELECT `uid`,`main` from `$users` WHERE `nick`='$nick1'"));
$main = $uid1[1];
$uid1 = $uid1[0];
// arrays uid0 and uid1 have been destroyed.

if(empty($uid0) || empty($uid1)) {
print "One or both of the nicknames were not found in the database. I thought I told you not to be careful? THERE IS NO IDIOT PROTECTION LIKE THIS";
return;
}

// set nick1 to not main
$query = "UPDATE `$users` SET `main`='' WHERE `uid`=$uid1";
print "$query<br/>";
$data0 = mysql_query($query);
// data0 = outside loop for show tables.
$data0 = mysql_query("SHOW TABLES");
while($table = mysql_fetch_row($data0)) {
// Go through all the tables and check to see whether they are a channel stats page
$table = $table[0];
if(preg_match("/^stats_/",$table)){
// data1 = inside loop to do inside loop stuff - To not disturb data0.
// Select all the data from nick1 and dump it into nick0
$data1 = mysql_query("SELECT * FROM `$table` WHERE `uid`='$uid1'");

while($row = mysql_fetch_assoc($data1)){
$lines = $row['lines'];
$questions = $row['questions'];
$lol = $row['lol'];
$urls = $row['urls'];
$kicks = $row['kicks'];
$kicked = $row['kicked'];
$joins = $row['joins'];
$swears = $row['swears'];
$acts = $row['acts'];
$wpl = $row['wpl'];
$query = "UPDATE `$table` SET `lines`=`lines`+$lines,`questions`=`questions`+$qu estions,`lol`=`lol`+$lol,`urls`=`urls`+$urls,`kick s`=`kicks`+$kicks,`kicked`=`kicked`+$kicked,`joins `=`joins`+$joins,`swears`=`swears`+$swears,`wpl`=` wpl`+$wpl,`acts`=`acts`+$acts WHERE `uid`='$uid0'";
$data2 = mysql_query($query);
print "$query<br/>";
// Delete old entries from table
$query = "DELETE FROM `$table` WHERE `uid`='$uid1'";
$data2 = mysql_query($query);
print "$query<br/>";
}
}
}
// Afterwards, merge the UID's on the constant tables (the users table and the master stats table)
$query = "UPDATE `$master` SET `lines`=`lines`+$lines,`questions`=`questions`+$qu estions,`lol`=`lol`+$lol,`urls`=`urls`+$urls,`kick s`=`kicks`+$kicks,`kicked`=`kicked`+$kicked,`joins `=`joins`+$joins,`swears`=`swears`+$swears,`wpl`=` wpl`+$wpl,`acts`=`acts`+$acts WHERE `uid`='$uid0'";
$data2 = mysql_query($query);
print "$query<br/>";
// Now delete old entries from the master stats
$query = "DELETE FROM `$master` WHERE `uid`='$uid1'";
$data2 = mysql_query($query);
print "$query<br/>";
// Change the UID of nick1 to point to that of nick0
$query = "UPDATE `$users` SET `uid`=$uid0 WHERE `uid`=$uid1";
$data2 = mysql_query($query);
print "$query<br/>";
// Done!
} else {
?>
<p>Nick1 will be merged INTO nick0. Nick0 is the PRIMARY NICKNAME. There is currently no idiot protection on this, so don't circularly link anything! I don't know what it would do, nor do I want to find out.</p><br>
<SCRIPT LANGUAGE=JAVASCRIPT>
function verify(){
msg = "Submit Changes?";
return confirm(msg);
}
</SCRIPT>
<form id="form1" name="form1" method="post" action="mergeusers.php?submit=true" onsubmit="return verify()";>

Nick0:
<label>
<input type="text" name="nick0" />
</label>
<br/>
Nick1:
<label>
<input type="text" name="nick1" />
</label>
<br/>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
<?php
}
?>

Zok
05-30-2007, 07:56 PM
Just added some more to the panel. Now it has a memo manager so that you can add and remove memos from any channel.

Zok
07-22-2007, 05:02 AM
Admin CP is no longer being worked on. Instead the bot cp (its replacement) is being worked on. You can read about and see it in action at: http://bbs.zoklet.net/showthread.php?t=182