try to add "theme color change" user option (my code works for the admin)

Started by padexx, August 16, 2006, 07:35:24 AM

Previous topic - Next topic

padexx

Hi,

I am the author of the wow-dk theme. This theme contains different color schemes that I want to be selectable via the user-profile (each user has his personal color after login).

The code works fine on my local test servers but causes problems "online".

prifile.template.php
// color selection box
if(isset($settings['allow_color_change']) && $settings['allow_color_change'] == 'box')
echo '
<tr>
<td colspan="2" width="40%"><b>', $txt['theme_personal_color'], ':</b>
<form action="', $scripturl, '" method="post" class="smalltext">
<select name="options[theme_color]">
<option value="0" ' ,$settings['theme_default_color'] == '0' ? 'selected="selected"': '', '>Default Orc (horde/red)</option>
<option value="1" ' ,$settings['theme_default_color'] == '1' ? 'selected="selected"': '', '>Human (alliance/blue)</option>
<option value="2" ' ,$settings['theme_default_color'] == '2' ? 'selected="selected"': '', '>Draenei (alliance/blue)</option>
<option value="3" ' ,$settings['theme_default_color'] == '3' ? 'selected="selected"': '', '>Blood Elves (horde/red)</option>
<option value="4" ' ,$settings['theme_default_color'] == '4' ? 'selected="selected"': '', '>Elves (alliance/blue)</option>
<option value="5" ' ,$settings['theme_default_color'] == '5' ? 'selected="selected"': '', '>Undead (horde/green)</option>
<option value="6" ' ,$settings['theme_default_color'] == '6' ? 'selected="selected"': '', '>Dwarves (alliance/brown)</option>
<option value="7" ' ,$settings['theme_default_color'] == '7' ? 'selected="selected"': '', '>Gnomes (alliance/brown)</option>
<option value="8" ' ,$settings['theme_default_color'] == '8' ? 'selected="selected"': '', '>Troll (horde/red)</option>
<option value="9" ' ,$settings['theme_default_color'] == '9' ? 'selected="selected"': '', '>Tauren (horde/brown)</option>
<option value="10" ' ,$settings['theme_default_color'] == '9' ? 'selected="selected"': '', '>WOW LOGO (grey)</option>
</select>
<input type="submit" name="submit" value="Change" style="width: 11ex;" />
</form>
</td>
</tr>';


If I try to change the color I get this error:
QuoteAn Error Has Occurred!
The user whose profile you are trying to view does not exist.

I am no php expert. What did I do wrong?

Could someone please help me out? Thanks!
panic

JunFan

I'm not php expert myself, and only just now getting into SMF and related projects.  I'm at work and can't really look at the code on my system, so please pardon me for a stupid question, but looking at the code...

I'm a little confused by the form tag...  What's the value in $scripturl supposed to be?

In examining the source on my site, it looks like:

<tr>
<td colspan="2" width="40%"><b>Personal color of WoW-DK theme:</b>
<form action="http://councilofelders.net/smf/index.php" method="post" class="smalltext">
<select name="options[theme_color]">
<option value="0" >Default Orc (horde/red)</option>
<option value="1" >Human (alliance/blue)</option>
<option value="2" selected="selected">Draenei (alliance/blue)</option>
<option value="3" >Blood Elves (horde/red)</option>
<option value="4" >Elves (alliance/blue)</option>
<option value="5" >Undead (horde/green)</option>
<option value="6" >Dwarves (alliance/brown)</option>
<option value="7" >Gnomes (alliance/brown)</option>
<option value="8" >Troll (horde/red)</option>
<option value="9" >Tauren (horde/brown)</option>
<option value="10" >WOW LOGO (grey)</option>
</select>
<input type="submit" name="submit" value="Change" style="width: 11ex;" />
</form>
</td>
</tr>


The other forms on this page have an index.php?action=<something> in the url.  Maybe this is the problem?  (see here...)

<form action="http://councilofelders.net/smf/index.php?action=profile2" method="post" name="creator" id="creator">

<...snip...>

        <input type="submit" value="Change profile" />
        <input type="hidden" name="sc" value="b2d630f1ed154sd54fe1ddd5aa2744e" />
        <input type="hidden" name="userID" value="5" />
        <input type="hidden" name="sa" value="theme" />

</form>


Kinda also makes me think to make an actual submission you need to be passing the session cookie, userID and whatever "sa" is referencing...

padexx

Zhorne:

You were absolutely right!  ;) Don't know wehre my brain is at the moment...

please change
Quote<form action="', $scripturl, '" method="post" class="smalltext">
to
Quote<form action="', $scripturl, '?action=profile2" method="post" class="smalltext">

This solves the problem over here.

Please report if it works for you, too.

panic

JunFan

I'm still getting the error unless I'm a sys admin.

I'm still wondering if the issue is that Profile.php's modifyProfile2 function doesn't know how to handle your form inputs and what to change.

The error message is not posted to the smf logs either...but it complaining about User Profile Not Existing kinda jumps out to me as it saying "I don't know who you are, so I give up."  and that might be related to the modifyProfile2 function calling checkSession() (from Security.php) and not having any session information to pass it.

I'm going to hack it so that the color change form is part of the outter form for updating profile via action=profile2... and see where that goes.  It might be somewhat redundant to have a form with in a form here.

JunFan

Ok that worked better but it didn't change the color.

I'm new to SMF I'm not sure how the data flows exactly through the code between files, but by commenting the form tage just for the color change out I no longer see the user profile error for any user... the downside is the color doesn't change either.  I have verified that it is changing the theme_color option in the database, but the theme color is not being applied, nor is it being picked up when I return the theme/profile page... the preselected item is Default/Orc Red.

I'll keep digging deeper.

JunFan

Ok, I must have serious server caching standing in the way of changes to the theme showing up...

It's working for me.

I ended up removing your form all together.  Having it there makes for a little redundance, it was the only way I could get the session info to be included in the post vars other than copying the code for it...again redundant.

smf/Themes/TP_wowdk-e > diff Profile.template.php Profile.template.php.bak
1699a1700
>       <form action="', $scripturl, '" method="post" class="smalltext">
1712a1714,1715
>       <input type="submit" name="submit" value="Change" style="width: 11ex;" />
>       </form>

padexx


JunFan

Sorry, it's a unix diff command.... shows differences between two files.

Basically here's an explained example:

http://unixhelp.ed.ac.uk/utilities2/diff1.html

But in our instance, the first file is my version, the second is the original.  To make the first file in the diff command look like the second, we would need to add (a) the code from the 2nd file at line 1700-

<form action="', $scripturl, '" method="post" class="smalltext">

after (>) line 1699 in the first file.

The second part would mean add lines 1714 and 1715 from the 2nd file after line 1712 of the first file.

Sorry for the confusion, I often forget that php is popular on windows nowadays.

JunFan

Just to clarify my changes more clearly...  I removed the form tag and the submit button from your code so that your select option is just submitted by the "outer" form tag which has all the other changeable options associated with it.

// color selection box
if(isset($settings['allow_color_change']) && $settings['allow_color_change'] == 'box')
echo '
<tr>
<td colspan="2" width="40%"><b>', $txt['theme_personal_color'], ':</b>

<select name="options[theme_color]">
<option value="0" ' ,$settings['theme_default_color'] == '0' ? 'selected="selected"': '', '>Default Orc (horde/red)</option>
<option value="1" ' ,$settings['theme_default_color'] == '1' ? 'selected="selected"': '', '>Human (alliance/blue)</option>
<option value="2" ' ,$settings['theme_default_color'] == '2' ? 'selected="selected"': '', '>Draenei (alliance/blue)</option>
<option value="3" ' ,$settings['theme_default_color'] == '3' ? 'selected="selected"': '', '>Blood Elves (horde/red)</option>
<option value="4" ' ,$settings['theme_default_color'] == '4' ? 'selected="selected"': '', '>Elves (alliance/blue)</option>
<option value="5" ' ,$settings['theme_default_color'] == '5' ? 'selected="selected"': '', '>Undead (horde/green)</option>
<option value="6" ' ,$settings['theme_default_color'] == '6' ? 'selected="selected"': '', '>Dwarves (alliance/brown)</option>
<option value="7" ' ,$settings['theme_default_color'] == '7' ? 'selected="selected"': '', '>Gnomes (alliance/brown)</option>
<option value="8" ' ,$settings['theme_default_color'] == '8' ? 'selected="selected"': '', '>Troll (horde/red)</option>
<option value="9" ' ,$settings['theme_default_color'] == '9' ? 'selected="selected"': '', '>Tauren (horde/brown)</option>
<option value="10" ' ,$settings['theme_default_color'] == '9' ? 'selected="selected"': '', '>WOW LOGO (grey)</option>
</select>
</td>
</tr>';


I'll fully admit I don't know why this seemed to work and the other way you mentioned didn't.  The only thing that comes to mind is that the form containing the main submit button for the profile page also contains hidden inputs (which I noted in an earlier post above) that represent session information.  That is the only realy piece that makes sense to me... your form lacked those sessions variables, and thus produced an error that the user profile didn't exist.

I didn't find any errors in the smf logs or my apache logs which helped me come to this conclusion.  Just experience from working with many other web based portal/content/knowledge management products professionally made me think that might be a logical answer.

As a test, I would attempt to make the setting change, then query the database to see the theme_color variable's value for the user I was logged in as before and after the setting change.  Before I modified the template to remove the nested form tag, no database changes were being made.  Afterwards I could see the theme_color change between the values specified in the select list.  From there it was a matter of making sure I didn't have any lingering cache's between my browser and my server...took about 10 minutes of fiddling to do that... I'd reload and get the old color, check the DB see it was set differently and scratch my head.  Eventually it showed up as I expected.

padexx

First, thanks for putting so much work and time into this problem!

I agree with you (missing user id, session id, ...) and I tried the code with the removed form-tags. But the problem (on my site) is still there.
As the "solution" with
"', $scripturl, '?action=profile2"
your code too only works for me being sys-admin and not as normal user. Or did I missed something in your last posting?

JunFan

Check out http://councilofelders.net/smf register a user, I'll approve it, and you vn view source on my theme/layout profile page.  The site's a work in progress, only 5 days old, but I think with out being an admin you can effect a color change in your profile.

I'm at work and don't have direct access to the code on my site (and that was the case yesterday when I posted the last code snippet)... I copied the code from your original post and took the 3 lines out that I remembered removing...I may have made a mistake.

padexx

Registerd...

THX for your help! Will spend you a beer if it realy works  ;)

padexx

Sadly I have to say that it didn't work on your site, too!   :'(
As normal user I was not able to change the color of the theme...

JunFan

Yeah I'm confirming that myself now...

Interestingly enough I think there may be an issue here:


mysql> select a.membername, b. variable, b.value from smf_members a, smf_themes b where a.ID_MEMBER = b.ID_MEMBER and b.variable = 'theme_color';
+------------+-------------+-------+
| membername | variable    | value |
+------------+-------------+-------+
| Zhorne     | theme_color | 10    |
| Zhorne     | theme_color | 10    |
| Dracena    | theme_color | 4     |
| Dracena    | theme_color | 1     |
| Malown     | theme_color | 1     |
| Selae      | theme_color | 4     |
| padexx     | theme_color | 5     |
+------------+-------------+-------+
7 rows in set (0.03 sec)


Now I'll go change the color for Dracena and post the same query...


mysql> select a.membername, b. variable, b.value from smf_members a, smf_themes b where a.ID_MEMBER = b.ID_MEMBER and b.variable = 'theme_color';
+------------+-------------+-------+
| membername | variable    | value |
+------------+-------------+-------+
| Zhorne     | theme_color | 10    |
| Zhorne     | theme_color | 10    |
| Dracena    | theme_color | 8     |
| Dracena    | theme_color | 1     |
| Malown     | theme_color | 1     |
| Selae      | theme_color | 4     |
| padexx     | theme_color | 5     |
+------------+-------------+-------+
7 rows in set (0.00 sec)


Seems odd that my two users have two rows for the same setting.  It's clear that the first one read from the db is the first one taken.  Oddly enough, 10 is my default theme color.  I'm wondering if the option to set all users to a certain color causes an extra row to be added to the DB w/o cleaning the existing rows up.

Aside from that, it's alsow clear that I changed Dracena's from Elves to Trolls, and what's really odd is that all I see on Dracena's page is Human (theme_color 1)....as seen here (not the time stamp on the screenie it is after running both queries and a profile theme_color update from Elf to Troll)...


padexx

Hi,

I have completely rewritten the code!
AND it works... as far as I have tested it ;)

Updated theme to Version f

Please reinstall the theme. Don't just overwrite the files!

panic

JunFan


Advertisement: