NineChime forum

Furry stuff, oekaki stuff, and other stuff.

You are not logged in.

#1 09-24-2007 15:26:40

matthewst
Member

Special needs painter

I trying to "build" an online painter for some special needs children. The process of building an account and logging in is a problem for some of the kids ( we have a fairly high turnover rate so it would be a chore for me to keep up with as well) so I've been trying to get them directly to a page with various pictures on it (their face, my face, or whaterver). Here they can select a picture to draw on. They are then taken directly to shipainter with the choosen picture as the background. I've downloaded shipainter.jar and was able to get it up and running (including the background image) without any problems but I don't know how to get it into my database. I'm asking you for help because you're kung-fu is obviously superior to mine. Once the pictures are in the database I'll have no trouble getting them back out for display. I just don't know how to get the suckers in there.

In a nutshell:
I need a help building a version of waxpotato that has no login but still submits to a database so the kids can see what everyone else has drawn.




I've been working with php and mysql for a little under a year but your code is still well above my level.

Thanks for any guidance you are able to give.

Offline

#2 09-25-2007 06:50:27

matthewst
Member

Re: Special needs painter

I tried setting $OekakiU and $OekakiPass to user and pass respectively in functions.php. It didn't work.

Offline

#3 09-25-2007 07:46:47

Waccoon
Administrator

Re: Special needs painter

Although $OekakiU and $OekakiPass are always handled in boot.php for every entry point, there are many different ways that those two variables are initialized before boot.php filters them.

This is a bit of a problem, because the design of OekakiPoteto requires a username to be specified before drawing begins, and that username is sent to the board when the picture is submitted.  Then, the board will redirect to the comment screen by looking for the most recent drawing made by that member.  Without a username, a lot of things don't work properly and things tend to disappear.  Another problem is that the applet redirect has to be hard-coded, so it's not possible for the board to send a picture number to the applet, and then the applet would redirect to the appropriate picture.  It would be necessary to send a coded hash to the applet, which could then be decoded by the comment screen to make the match, and then discarded.  Making such matches isn't easy.  This is precisely why older oekaki boards, such as OekakiBBS, just submit pictures, and it was assumed that the first person to comment on the picture was the artist, which is a really lousy way of doing things!

I assume the way you'd like this to work is that after a drawing is submitted, someone would enter their name, so everyone knows who drew what picture.  Passwords and the like aren't required.  If so, the coded hash method is probably the best compromise, but I'd have to think about which stable hash would be ideal.  A truncated microtime stamp would probably do the trick, since security wouldn't be critical.

If you only need to have all the pictures sent under the same username, you'd just have to register a single account, then modify boot.php so the name and password are always used.  For Wax 5.6.1, that begins on line 121:

Code:

if (!isset ($OekakiU) && !isset ($OekakiPass)) {
    $OekakiU    = '';
    $OekakiPass = '';
    if (isset ($_COOKIE['OekakiU']) && isset ($_COOKIE['OekakiPass'])) {
        $OekakiU    = $_COOKIE['OekakiU'];
        $OekakiPass = $_COOKIE['OekakiPass'];
    }
}

A start would be to always log in with the account you've created, so replace the above with this:

Code:

// Force login
{
    $my_account_name = 'name';

    $OekakiU = addslashes ($my_account);
    $result = mysql_query ("SELECT usrpass FROM {$OekakiPoteto_MemberPrefix}oekaki WHERE usrname='{$OekakiU}'");
    if ($result) {
        // Get the properly encrypted password from the database
        $OekakiPass = mysql_result ($result, 0);
    } else {
        // Database error.  We can't do much except refresh
        exit ('Please click the refresh button on your web browser');
    }
}

That should always log in the account automatically, and thus transmit all the proper info to the applets, unless I missed something.  Be aware that with this hack, only one person may draw at a time, or you'll have a lot of pictures showing up in the recovery bin, and you'll be "locked out" of the admin account for recovering them.

Offline

#4 09-25-2007 10:39:19

matthewst
Member

Re: Special needs painter

You are the master!

I had to change this:

Code:

$OekakiU = addslashes ($my_account);

to this:

Code:

$OekakiU = addslashes ($my_account_name);

And I hadn't thought about this:

Code:

Be aware that with this hack, only one person may draw at a time,

Trying to simplify this as much as possible...so I can understand.
$picture is chosen on another page and passed to the below file (shipainter.php) . When I click "upload" in shipainter I get this error "protocol doesn't support output SendE". I know I get that because with this simple script I don't have a database defined, or where to put the picture in the database. In the past I've built forms that upload to the database so I know I can do that much. What I don't know is how do I transition from shipainters upload button to php. I have know idea where to start.

Example:
A user chooses a background image from image_select.php and is automaticly redirected to shipainter //already built and functioning
The image is loaded into shipainter via the $picture variable //already functioning
The user does some drawing and clicks submit
//normaly this is where I would have a form submit to a handler page ///////if ($action == "Submit"){then do some stuff}
//but shipainter doesn't work like that. This is where I need the help.
The image is uploaded to the database via a handler page //I'll give it a name based on the timestamp
Users are then redirected to a gallery page with all the images displayed //I can build this without a problem

I don't need the script written for me I just need a push in the right direction. Thank you for the help you've already given.


Code:

<?php
if ($submit)
{//upload pic to database;
//then redirect to gallery;}
?>
<html>
<head>
<title>Shi-Painter</title>
<script language="javascript" type="text/javascript" src="sp.js"></script>
</head>
<body>
<applet code="c.ShiPainter.class" name="paintbbs" archive="spainter_all.jar,res/normal.zip" WIDTH="100%" height="90%" MAYSCRIPT>
<param name="image_width" value="1100" />
<param name="image_height" value="800" />
<param name="image_canvas" value="<?php echo '$picture'; ?>" />

<param name="dir_resource" value="./res/" />
<param name="tt.zip" value="./res/tt.zip" />
<param name="res.zip" value="./res/res_normal.zip" />
<param name="tools" value="normal" />
<param name="layer_count" value="3" />
<param name="quality" value="1" />

<param name="undo_in_mg" value="15" />
<param name="undo" value="30" />
<param name="MAYSCRIPT" value="true" />
<param name="scriptable" value="true" />


<param name="color_text" value="0" />
<param name="color_bk" value="#FFFF0" />
<param name="color_bk2" value="#FF00FF" />
<param name="color_icon" value="#0FFFF" />
<param name="color_frame" value="0xff" />

<param name="color_iconselect" value="#112233" />
<param name="color_bar" value="0" />
<param name="color_bar_hl" value="#665544" />
<param name="color_bar_shadow" value="#778899" /> 

<param name="tool_color_bk" value="#aabbcc" />
<param name="tool_color_button" value="#ddeeff" />
<param name="tool_color_button_hl" value="#9900ff" />
<param name="tool_color_button_dk" value="#ff0099" />

<param name="tool_color_button2" value="#ffffff" />
<param name="tool_color_text" value="0" />
<param name="tool_color_bar" value="#00ff00" />
<param name="tool_color_frame" value="#ff0000" />



<param name=pro_menu_color_text value="#FFFFFF" />
<param name=pro_menu_color_off value="#222233" />
<param name=pro_menu_color_off_hl value="#333344" />
<param name=pro_menu_color_off_dk value="0" />
<param name=pro_menu_color_on value="#ff0000" />
<param name=pro_menu_color_on_hl value="#ff8888" />
<param name=pro_menu_color_on_dk value="#660000" />

<param name=bar_color_bk value="#ffffff" />
<param name=bar_color_frame value="#ffffff" />
<param name=bar_color_off value="#ffffff" />
<param name=bar_color_off_hl value="#ffffff" />
<param name=bar_color_off_dk value="#ffffff" />
<param name=bar_color_on value="#777777" />
<param name=bar_color_on_hl value="#ffffff" />
<param name=bar_color_on_dk value="#ffffff" />
<param name=bar_color_text value="0" />

<!--ƒEƒCƒ“ƒhƒEŠÖŒW‚Ì Ý’è-->
<param name="window_color_text" value="#ff0000" />
<param name="window_color_frame" value="#ffff00" />
<param name="window_color_bk" value="#000000" />
<param name="window_color_bar" value="#777777" />
<param name="window_color_bar_hl" value="#888888" />
<param name="window_color_bar_text" value="#000000" />

<!--Šm”FƒEƒCƒ“ƒhƒE‚Ì Ý’è-->
<param name="dlg_color_bk" value="#ccccff" />
<param name="dlg_color_text" value="0" />

<!--ƒAƒvƒŒƒbƒg‚Ì”wŒi‚Ì Ý’è-->
<param name=color_bk value="#ccccff" />
<param name=color_bk2 value="#f0f0f0" />

<!--ƒŒƒCƒ„ [‚̃  [ƒ^ [ƒJƒ‰ [‚Ì Ý’è-->
<param name=l_m_color value="#ffffff" />
<param name=l_m_color_text value="#0000ff" />
</applet>

</body>

<script language="javascript">
<!--
document.write('<form name="a"><input type="button" name="b" value="bn.gif" onClick="sAddImage(\'bn.gif\',2,100,10);"></form>');
//-->
</script>
</html>

Last edited by matthewst (09-25-2007 14:07:54)

Offline

#5 09-26-2007 06:45:46

matthewst
Member

Re: Special needs painter

In a nutshell I just need to know how to get ahold of the image variable. I know how to upload images using php and mysql I just don't know how to "grab" the image from shipainter.

Offline

#6 09-27-2007 07:05:09

matthewst
Member

Re: Special needs painter

When a person clicks submit in php all the form fields are then passed to the form handler and the field names are automaticaly turned into variables. I need the $image variable.

I know uploading pictures is a little different. Here is a snippet of code I've used in the past for image uploading:
$path= "$root_folder_img/".$HTTP_POST_FILES['upload_image]['name'];
if($upload_image !=none)
{
if(copy($HTTP_POST_FILES['upload_image']['tmp_name'], $path))
{
echo "Successful<BR/>";}}


How do I get ahold of "upload_image" from shipainter? Do I just change upload_image to shi-painter or something like that?

Offline

#7 09-27-2007 07:39:42

Waccoon
Administrator

Re: Special needs painter

protocol doesn't support output SendE

When you send image data to the server, the script has to return a confirmation that it received the data correctly.  If the applet gets no confirmation, you will get this error.

There's quite a few things missing in that code you posted.  For starters:

Code:

<param name="url_save" value="shiget.php" />
<param name="url_exit" value="comment.php" />

ShiPainter sends the data to "url_save", and if it receives the confirmation code, it will redirect to "url_exit".  The actual picture number is never sent to the applet, so when the applet redirects, you have to search for the last picture posted by the artist.  That's why if you set up a board without a login, only one person can use the board at a time.  Otherwise, there's no way to tell which picture is which.

...also note:

Code:

<param name="image_canvas" value="<?php echo '$picture'; ?>" />

Here, you either have to get rid of the apostrophes, or use double quotes for the $picture variable to parse as expected.  Apostrophes tell PHP to treat the string as a literal, so it will actually print '$picture' instead of the value of the variable.  Double quotes tell PHP to parse the string and replace variable names with their values.  Putting curley brackets around variables helps clear up confusion:

Code:

RIGHT:
echo ('My name is' . $name);
echo ("My name is $name");
echo ("My name is {$name}");

WRONG:
echo ('My name is $name');
echo ('My name is {$name}');

In a nutshell I just need to know how to get ahold of the image variable.

Unfortunately, none of the applets use forms to upload files (as they should), so a lot of frustrating things happen.  First, getting cookies is a pain, but thankfully you don't have to deal with that.  Second, you can't just read a variable from the applet.  You have to read standard input (the entire chunk of data sent by the applet), and then break it up into smaller pieces.  ShiPainter formats its data with a header which tells you how big each piece is, and how many pieces there are.  All the code to do this is in shiget.php.

Code:

// Get raw POST data (reference test saves memory)
if (empty ($HTTP_RAW_POST_DATA)) {
    $raw_buffer = file_get_contents ('php://input');
} else {
    $raw_buffer =& $HTTP_RAW_POST_DATA;
}

// ShiBBS data
if (substr ($raw_buffer, 0, 1) == 'S') {
    // Image data
    $image['o_length'] = substr ($raw_buffer, $image['h_length'] + 9, 8);
    $image['o_length'] = (int) $image['o_length'];
    $image['o_data']   = substr ($raw_buffer, $image['h_length'] + 19, $image['o_length']);

    // Animation
    $image['t_length'] = substr ($raw_buffer, $image['h_length'] + $image['o_length'] + 19, 8);
    $image['t_length'] = (int) $image['t_length'];
    $image['t_data']   = substr ($raw_buffer, $image['h_length'] + $image['o_length'] + 27, $image['t_length']);

    // Thumbnail
    $image['t2_length'] = substr ($raw_buffer, $image['h_length'] + $image['o_length'] + $image['t_length'] + 27, 8);
    $image['t2_length'] = (int) $image['t2_length'];
    $image['t2_data']   = substr ($raw_buffer, $image['h_length'] + $image['o_length'] + $image['t_length'] + 35, $image['t2_length']);
}

In this code, standard input is read and put or referenced into the variable "$raw_buffer".  The picture data is put into "$image['o_data']", the animation data into "$image['t_data']", and the thumbnail into "$image['t2_data']".  Please note that picture data is always sent, but animation and thumbnail data require you to provide some extra applet parameters to enable them.

Once this data is parsed and saved, and the database has been updated, you need to send the confirmation to the applet to let it know that the upload was successful.  The "print_ok()" and "quiet_exit()" functions show the proper format.  If you send nothing, the applet will complain.  If you send anything without the "text/plain" MIME type, the applet will simply print that to the screen (and very poorly, too).

I'll have to help out with the code cleanup and database stuff tomorrow.  Right now, it's time for bed.  smile

Offline

#8 09-27-2007 12:40:02

matthewst
Member

Re: Special needs painter

I can't thank you enough wac. I'll post everything I have ASAP so you can take a look at it.

Offline

#9 09-28-2007 05:08:30

Waccoon
Administrator

Re: Special needs painter

That's good.  It's easy to look at existing code.  smile

As far as the database is concerned, that can be difficult.  There's a lot of things you have to think about when getting/sending data to the database, and setting up the database is the hardest part.  Then again, if you're using this code for your own purposes, you don't have to worry about making the code as generic and portable as possible, which is a big help.

Offline

#10 09-28-2007 07:51:41

matthewst
Member

Re: Special needs painter

As far as the database is concerned, that can be difficult.

I've still got your database built by wax potato if that helps

Ok here is pic_chooser.php

Code:

<html>
<body>
<form name="form1" method="post" action="spainter.php" >
<input type="image" name="picture" src="picture1.jpg">
<input type="hidden" name="picture" value="picture1.jpg">
</form>

<form name="form2" method="post" action="spainter.php" >
<input type="image" name="picture" src="picture2.jpg">
<input type="hidden" name="picture" value="picture2.jpg">
</form>

</body>
</html>

Here is the code I'm using in spainter.php (from sptr_all1114.zip)

Code:

<param name="image_canvas" value="<?php echo $picture; ?>" />

Last edited by matthewst (09-28-2007 07:53:56)

Offline

#11 09-28-2007 09:34:29

matthewst
Member

Re: Special needs painter

A thought just hit me about the artist name, database thing. I can use php to generate a random string of characters to pass to the database as the username. There won't be any retuouches or safety saves, but we won't be needing them anyway.

Offline

#12 10-03-2007 12:11:57

matthewst
Member

Re: Special needs painter

Here is my shiget.php

Code:

<?php
// Get raw POST data (reference test saves memory)
if (empty ($HTTP_RAW_POST_DATA)) {
    $raw_buffer = file_get_contents ('php://input');
} else {
    $raw_buffer =& $HTTP_RAW_POST_DATA;
}
// Load bootstrap, quiet mode
$OekakiU    = "test_user";
$OekakiPass = "password";
// Test input
if (empty ($raw_buffer)) {
    // No data to save!
    quiet_exit($langop_err_nodata);
}
if (substr ($raw_buffer, 0, 1) != 'S') {
    quiet_exit($langop_poo_compat." '<param name=\"poo\" value=\"false\" />'");
}
// ShiBBS data
if (substr ($raw_buffer, 0, 1) == 'S') {
    // Image data
    $image['o_length'] = substr ($raw_buffer, $image['h_length'] + 9, 8);
    $image['o_length'] = (int) $image['o_length'];
    $image['o_data']   = substr ($raw_buffer, $image['h_length'] + 19, $image['o_length']);
// Write files
//
// Save image/anim data.  Filetype is automatic!
if (!save_image($image['o_data'], $resno)) {
    w_error_log (__FILE__.": Cannot save image.  Look for temp image.  User: $OekakiU, Number: $resno");
    quiet_exit($langop_err_saveimg);
}
int_ok();
?>

I now get a shiny new error message!

Code:

 Server returned HTTP response code: 403 for URL: http://servername/dir/getpic.cgi
SendE

Offline

#13 10-04-2007 04:05:25

Waccoon
Administrator

Re: Special needs painter

OK, we've got several problems, here.

First, you don't really have to modify the shiget.php code.  The value of $OekakiU and $OekakiPass are retrieved from the applet with this code:

Code:

$OekakiU    = addslashes (utf8_decode ($params['usr']));
$OekakiPass = addslashes ($params['vcode']);

What this means is that the applet will send an encoded header to the script.  This header is decoded into the $params[] array at the top of the code as an unescaped UTF-8 string.

So long as you have a custom user name and password hard-coded into boot.php, you don't have to worry about changing $OekakiU and $OekakiPass in any other script.  boot.php takes care of all that, and passes the values to the applets automatically.

Server returned HTTP response code: 403 for URL: http://servername/dir/getpic.cgi

Well, there's no "getpic.cgi" file to be found!  We're not using a Perl script (the "cgi" file extension), we're using PHP.  wink

Also note that boot.php handles the database connection, so if you fail to include that, you can't insert the picture, and there's database code in shiget.php that MUST be left intact.  Quite simply, this code isn't usable, because there's too much missing.

It's actually quite tricky to change the code so guests can type in their names.  OekakiPoteto wasn't designed with that in mind, and it's something I'll have to think about with my next board.

Really, it's functions.php, comment.php, and paintsave.php that require modification to do what you need.  The hard part is forcing a login so people can draw, but shadowing the login when they post a comment, so the board thinks that person is a guest, and therefore, their name is requested.

See, I'm not sure how sophisticated it should be if it's a "special needs" board.  Do these children have specific visual or physical disabilities that makes it hard for them to type or read small text?  If so, changing the templates would be a big help on top of code changes.

Sorry, but during the week I don't have much time to help out.  If you can tell me a bit more about the procedure you'd like for people to draw, I can hack up some code for you on the weekend that might give you a better idea of what's going on when a picture is submitted.

Offline

#14 10-04-2007 06:54:23

matthewst
Member

Re: Special needs painter

Most of the kids can see ok, typing is an isssue and so is understanding what the applet is asking for(confirmation, name, comments etc).
Do I even need a database or can I just upload the images to a dir on my server?
I'll be working on what you suggested today, I'll post my results.

once again Thank you!

Offline

#15 10-10-2007 08:38:04

matthewst
Member

Re: Special needs painter

I don't know what happened, the whole thing self destructed this morning. I've had to start completely over.

Offline

#16 10-12-2007 11:03:39

matthewst
Member

Re: Special needs painter

I'm finally back to where I started.

Offline

#17 10-13-2007 06:30:01

Waccoon
Administrator

Re: Special needs painter

Sorry for the wait.  It's been hectic this week at work before my vacation.  But, I have this week off, so after I get some sleep, I'll see what I can do for you.  I spent all night getting art done.  wink

The short of it is that you'll have to have a modified version of the board that is aware of guests.  You don't really need to make too many changes to the applet parsing code, but you DO have to make changes to the authorization system and the comment system.

Offline

Board footer

Yep, still running PunBB
© Copyright 2002–2008 PunBB