ckyshop.co.uk Posted September 3, 2005 Share Posted September 3, 2005 Hey Just wondering if you could give me some help. Here's what I'm trying to do: I want to have 3 stylesheets, and let the customer choose what colour scheme they want. This is done by a drop down menu, like for currencies. I can get it to work for one page, they select the scheme from the menu and the stylesheet switches accordingly. But when they navigate away from the main page, the one with the '?stylesheet=2' in the address bar it switches back to default - I am guessing I need to add the string, which is set to '1', '2' or '3' to the session? Here is the code I think you may need: from the drop down menu: <tr> <td> <?php $style_selecta_array = array ( '0' => array ( 'id' => '1', 'text' => 'Black/Red' ), '1' => array ( 'id' => '2', 'text' => 'White/Blue' ), '2' => array ( 'id' => '3', 'text' => 'White/Orange' ), ); $info_box_contents = array(); $info_box_contents[] = array('text' => BOX_HEADING_STYLE); new infoBoxHeading($info_box_contents, false, false); /* reset($currencies->currencies); $currencies_array = array(); while (list($key, $value) = each($currencies->currencies)) { $currencies_array[] = array('id' => $key, 'text' => $value['title']); } */ $hidden_get_variables = ''; reset($HTTP_GET_VARS); while (list($key, $value) = each($HTTP_GET_VARS)) { if ( ($key != 'stylesheet') && ($key != tep_session_name()) && ($key != 'x') && ($key != 'y') ) { $hidden_get_variables .= tep_draw_hidden_field($key, $value); } } $info_box_contents = array(); $info_box_contents[] = array('form' => tep_draw_form('lewis', tep_href_link(basename($PHP_SELF), '', $request_type, false), 'get'), 'align' => 'center', 'text' => tep_draw_pull_down_menu('stylesheet_preference', $style_selecta_array, $selected_style_selecta_style, 'onChange="this.form.submit();" style="width: 100%"') . $hidden_get_variables . tep_hide_session_id()); new infoBox($info_box_contents); ?> </td> </tr> from application_top.php that will alter which stylesheet is loaded: // stylesheet preferences //if (!session_is_registered('stylesheet_preference')) { if (!tep_session_is_registered('stylesheet_preference') || isset($HTTP_GET_VARS['stylesheet_preference']) || ( (tep_session_is_registered('stylesheet_preference') && ($stylesheet_preference != $HTTP_GET_VARS['stylesheet_preference']) )) ) { if (isset($HTTP_GET_VARS['stylesheet_preference'])) { $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); tep_session_register('stylesheet_preference'); } else { $stylesheet_preference = '1'; tep_session_register('stylesheet_preference'); } } switch ($stylesheet_preference) { case 1: $stylesheet_preference_file = 'stylesheet1.css'; $stylesheet_bg_color = 'black'; $stylesheet_formline_color = 'ff9933'; $selected_style_selecta_style = '1'; break; case 2: $stylesheet_preference_file = 'stylesheet2.css'; $stylesheet_bg_color = 'white'; $stylesheet_formline_color = '0000ff'; $selected_style_selecta_style = '2'; break; case 3: $stylesheet_preference_file = 'stylesheet3.css'; $stylesheet_bg_color = 'white'; $stylesheet_formline_color = 'ff9933'; $selected_style_selecta_style = '3'; break; default: $stylesheet_preference_file = 'stylesheet1.css'; $stylesheet_bg_color = 'black'; $selected_style_selecta_style = '1'; break; } // stylesheet preferences // end Apart from not transferring from page to page I think it works OK. Thanks for taking a look - I wouldn't ask only I've been pulling my hair out for over a day (and it was sunny outside!!) Cheers Lewis Thanks for any help/comments. Regards, Lewis Hill Link to comment Share on other sites More sharing options...
Beer Monster Posted September 3, 2005 Share Posted September 3, 2005 if (!tep_session_is_registered('stylesheet_preference') && isset($HTTP_GET_VARS['stylesheet_preference'])) { ? $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); ? tep_session_register('stylesheet_preference'); ? $this->stylesheet_preference=$stylesheet_preference; } elseif (tep_session_is_registered('stylesheet_preference') && isset($HTTP_GET_VARS['stylesheet_preference'])){ ? $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); ? $this->stylesheet_preference=$stylesheet_preference; } else { ? $stylesheet_preference = '1'; ? tep_session_register('stylesheet_preference'); ? $this->stylesheet_preference=$stylesheet_preference; ?} Possibly, not tested it! Light, in the absence of eyes, illuminates nothing. Link to comment Share on other sites More sharing options...
ckyshop.co.uk Posted September 5, 2005 Author Share Posted September 5, 2005 if (!tep_session_is_registered('stylesheet_preference') && isset($HTTP_GET_VARS['stylesheet_preference'])) { ? $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); ? tep_session_register('stylesheet_preference'); ? $this->stylesheet_preference=$stylesheet_preference; } elseif (tep_session_is_registered('stylesheet_preference') && isset($HTTP_GET_VARS['stylesheet_preference'])){ ? $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); ? $this->stylesheet_preference=$stylesheet_preference; } else { ? $stylesheet_preference = '1'; ? tep_session_register('stylesheet_preference'); ? $this->stylesheet_preference=$stylesheet_preference; ?} Possibly, not tested it! <{POST_SNAPBACK}> Thanks for that! I added one more if statement and it now seems to be working! Hope it stays that way! Code is now: if (!tep_session_is_registered('stylesheet_preference') || isset($HTTP_GET_VARS['stylesheet_preference'])) { $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); session_register('stylesheet_preference'); $this->stylesheet_preference=$stylesheet_preference; } elseif (tep_session_is_registered('stylesheet_preference') && isset($HTTP_GET_VARS['stylesheet_preference'])){ $stylesheet_preference = ($HTTP_GET_VARS['stylesheet_preference']); $this->stylesheet_preference=$stylesheet_preference; } else { if(!tep_session_is_registered('stylesheet_preference')) { $stylesheet_preference = '1'; session_register('stylesheet_preference'); $this->stylesheet_preference=$stylesheet_preference; } } Thanks for any help/comments. Regards, Lewis Hill Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.