NineChime forum

Furry stuff, oekaki stuff, and other stuff.

You are not logged in.

#1 11-28-2005 11:46:38

Kameloh
Member

[programming help] Reading flags from another row

I'm posting here 'cause I'm scared that Poet is going to get mad at me XD (sorry poet!)

What I would like to do is integrate oekakis together using a one member database, but still allowing different boards with different administrators to modify flags of users. Basically, I want each board to have their own row in the MySQL op_oekakioekaki table.

myboard.php (this will be included on each page)

<?
$myboard = xyzboardname;
?>

Instead of reading the row usrflags, I want it to read $myboard. Poet suggested that I use the following when getting a mysql_query: (replaced usrflags with the bolded shown below)

$result = mysql_query("SELECT usrname, `".$myboard."` FROM ".$OekakiPote

And it works perfectly. The only problem I'm having right now is the !check_flag commands (shown in flagchk.php)

It's a problem because I know that it resides in the oekaki/painter/shi php files and I really have no idea how to fix them (though I have a good understanding how they 'work' - thanks to Poet)

flagchk.php

function check_flag($c) {
    global $usrflags;
    return is_integer(strpos($usrflags, $c));

I guess my first question right now is how to make it read from $myboard instead..

Well, I dunno. Do you think it's possible to integrate multiple boards all together using one member-database? XD

Offline

#2 11-30-2005 05:43:38

Waccoon
Administrator

Re: [programming help] Reading flags from another row

I'm not quite sure what you're trying to do here.

So, you have one monolithic database that has every member in it for all your boards combined.  When people register for boards, the "myboard" value is added to the database, so people know to which board they belong.  I take it you want some admins to be restricted to the boards where they have regitered (by checking the $myboard value), but some admins, like superadmins, are allowed to administrate the entire database.

And it works perfectly.

It shouldn't.  The value of $myboard is being used to access a column in the database.  So, if the value of $myboard is "xyzboardname", the SQL statement is trying to get information from a column named "xyzboardname", so your database would have to be set up like this:

Code:

ID | usrname | usrpass | usrflags | xyzboardname |     email
---+---------+---------+----------+--------------+----------
 1 |      me |     xxx |      GDM |       board1 | me@me.com

where xyzboardname is treated literally.

I think what you want to do is check which board belongs to each member:

Code:

ID | usrname | usrpass | usrflags |        board |     email
---+---------+---------+----------+--------------+----------
 1 |      me |     xxx |      GDM | xyzboardname | me@me.com
 2 |     you |     xxx |      GDM |       board2 |   u@u.com

To do this, you need to rewrite the SQL statement:

Code:

$result = mysql_query("SELECT usrname, board FROM ".$OekakiPotet... ;
$row = mysql_fetch_array($result);
if ($row['board'] == $myboard) {
   ...

What column name did you use to identify boards?

The only problem I'm having right now is the !check_flag commands (shown in flagchk.php)

The old flag check code from Wax is pretty terrible.  It expects all variables to be extracted, and then imported into the function as a global.  Extraction is where columns from the database are remapped to variables within the scope of the current code block.  So, after fetching info from the database, there will be a number of variables automatically created.  $usrname will be set, as will be $usrflags, and $usrpass, and so on.  This is really, really bad code, and I completely redid this in Wacintaki.  The proper way to do it is to keep everything in an array, and access them as $row['usrname'], $row['usrflags'], and so on.

Basicly, after you fetch the flags from the database, you need to define a root global "$usrflags" in the main code, as follows:

Code:

DO THIS FOR ONE VARIABLE:
$row = mysql_fetch_array($result);
$usrflags = $row['usrflags'];

OR THIS, TO DO ALL THE VARIABLES:
$row = mysql_fetch_array($result);
extract($row);

Once this is done, the check_flag() function will be able to import the flags in the $usrflags variable as a global.  If you don't manually set $usrflags, it will be blank (undefined), and the check_flag() function will always fail.

Well, I dunno. Do you think it's possible to integrate multiple boards all together using one member-database? XD

It's difficult with the existing code, as Oekaki Poteto wasn't really designed to do that.  You can do it, but make sure you really, really understand how the entire board works, as you'll be editing a LOT of code to make sure everything works.  I don't recommend any changes other than just allowing admins to change user flags, or lots of things can get broken or buggy very quickly.

Trust me, I've been working on this for a long time.  Wacintaki was just supposed to be a mod of Poteto for my own purposes, and it's grown into a real monster.  I think most programs are just grown this way.  smile

I really want to dump OP all together and make my own board from scratch, which is why 1.3 will be the last version of Wacintaki.  After that, I don't know who's going to take it over.  Wax will have a similar fate after the release of 5.6.

Offline

#3 12-01-2005 15:04:37

Kameloh
Member

Re: [programming help] Reading flags from another row

Ah thank you! So far I made the oekaki able to read the user's userflags from another row (and I've modified a lot of things throughout wax poteto)

The only problem I have right now is the security - especially with those using the !check_flag command (modflags.php, etc)

I was wondering if there's anyway to replace the following code with something else:

if ((!check_flag('O')) && (!check_flag('S')) && (!check_flag('A'))) {
    header('Location: error.php?error='.urlencode('You do not have the credentials to access flag modification.'));
    exit;
}

I looked through upload.php, and it does something like this: (note: I modified it so that it'll read from $myboard instead of 'usrflags' .. and it works XD)

$is_admin = 0;
if (strstr($row[$myboard],'O') || strstr($row[$myboard],'S') || strstr($row[$myboard],'A')) {
    $is_admin = 1;
}
if ($OekakiPass != $row['usrpass'] || !($is_admin || strstr($row[$myboard],'U'))) {
    mysql_close($dbconn);
    header('Location: error.php?error='.urlencode('You do not have the credentials to upload pictures.'));
    exit;
}

I've been trying to do that with modflags.php but I'm not sure if it's working or anything.. do you have any suggestions?

Offline

#4 12-03-2005 19:38:53

Waccoon
Administrator

Re: [programming help] Reading flags from another row

I was wondering if there's anyway to replace the following code with something else:

You can replace multiple calls to this code by setting an admin flag ($is_admin), though you would have to add this at the top of each script that requires an admin test.  This is why I created boot.php for Wacintaki -- it replaces all the wretched string tests.  However, boot.php had to be written in a special way so it won't choke when applets are sending picture data, since all the applets send data as raw POST data, instead of multipart encoded CGI data (why they don't do this baffles me.  It would make everything soooo much easier!)

A substitute would be a simpler admin check function, which would take $usrflags as a parameter.  Add it to flagcheck.php:

Code:

function check_admin($c) {
    if (strstr($c, 'O') || strstr($c, 'S') || strstr($c, 'A'))
        return TRUE;
        
    return FALSE;
}

Use it as:

if (check_admin ($usrflags)) {

Offline

Board footer

Yep, still running PunBB
© Copyright 2002–2008 PunBB