<id>
Style Switcher for YaBB 2.6.11
</id>

<version>
1.8
</version>

<mod info>
Features:
This mod allows a quick design change by using multiple template stylesheet in combination with a simple dropdown box. The last setting is save by a cookie. You can enable/disable these options in your admin center and select the membergroups allowed to use the Style Switcher.

Installation:

Use BoardMod or manually edit files.
Upload:

- Admin/Modlist.pm
- Admin/ManageTemplates.pm
- Admin/Settings_Main.pm
- Admin/NewSettings.pm
- Sources/Load.pm
- Sources/Subs.pm
- Languages/English/Admin.lng
- Languages/English/Main.lng
- Templates/default/default.html
</mod info>

<author>
Updated for 2.6.11 by Dandello on 01.13.2015
Updated for 2.6.1 by Dandello on 05.09.2014
Updated for 2.6.0 by Dandello on 09.07.2014
Updated - New settings by ThM on 27.10.2010
Updated again for YaBB 2.5 by Carsten.
Updated for YaBB 2.5 AE by ThM & Andi Kanzler - 4.7.2010
Updated for YaBB 2.3.1 January 08th, 2009 Version 1.1 for YaBB 2.3
updated by ThM - 27.10.2008 Version 1.0 for YaBB 2.2.2 by Thomas Mueller (ThM) - 16.06.2008
Special Thanks goes to AK108 for the permission to use his Set Template in URL 1.0 for YaBB 2.0/2.1 Mod for a YaBB 2.2.2 mod, to Namster for permission to use his Style Sheet Sets and to Deti for a little bit Support. Thanks Guys.
</author>

<homepage>
http://www.yabbforumsoftware.com
</homepage>

<edit file>
Admin/ModList.pm
</edit file>

<search for>
### END BOARDMOD ANCHOR ###
</search for>

<add before>
    $styleswitch = q~Style Switcher for YaBB 2.6.11|Thomas Mueller (ThM) Andi Kanzler &amp; Carsten|This mod allows a quick design change by using multiple template stylesheet in combination with a simple dropdown box. The last setting is save by a cookie. You can enable or disable these options and select to allow membergroups to use the Style Switcher in your admin center. This mod based on the AK108 YaBB 2.1 set template in url add-on. Thanks to him!|1.8|Jan 13, 2015~;
    push @installed_mods, $styleswitch;
</add before>

<edit file>
Admin/ManageTemplates.pm
</edit file>

<search for>
    $fulltemplate =~ s/({|<)yabb time(}|>)/$temptime/gsm;
</search for>

<add after>
    $fulltemplate =~ s/({|<)yabb styleswitch(}|>)/$yystyleswitch/gsm;
    $fulltemplate =~ s/({|<)yabb tempswitcher(}|>)/$yytempswitcher/gsm;
</add after>

<edit file>
Admin/Settings_Main.pm
</edit file>

<search for>
        {
            description => qq~<label for="default_template">$admin_txt{'813'}</label>~,
            input_html => qq~<select name="default_template" id="default_template">$drawndirs</select>~,
            name => 'default_template',
            validate => 'text',
        },
</search for>

<add after>
        { # Style Switcher MOD START
            description =>qq~<label for="templ_switcher">$admin_txt{'813a'}</label>~,,
            input_html => qq~<input type="checkbox" name="templ_switcher" id="templ_switcher" value="1"${ischecked($templ_switcher)} />~,
            name => 'templ_switcher',
            validate => 'boolean',
        },
        {
            description => qq~<label for="temp_switcher_allowed">$admin_txt{'813b'}</label>~,
            input_html => qq~
            <select name="temp_switcher_allowed" id="temp_switcher_allowed">
            <option value="0" ${isselected($temp_switcher_allowed == 0)}>$userlevel_txt{'all'}</option>
            <option value="1" ${isselected($temp_switcher_allowed == 1)}>$userlevel_txt{'members'}</option>
            </select>~,
            name => 'temp_switcher_allowed',
            validate => 'number',
        }, # Style Switcher MOD END
</add after>

<edit file>
Admin/NewSettings.pm
</edit file>

<search for>
\$default_template = "\Q$default_template\E";   # Default Forum Template
</search for>

<add after>
\$templ_switcher = "$templ_switcher";           # Set to 1 to display the template switcher dropdown field and allow a quick style switch
\$temp_switcher_allowed = $temp_switcher_allowed;   # minimum user level for show Style Switcher: 0 = all, 1 = only members
</add after>

<edit file>
Sources/Load.pm
</edit file>

<search for>
    if ( ${ $uid . $username }{'template'} ne q{} ) {
        if ( !exists $templateset{ ${ $uid . $username }{'template'} } ) {
            ${ $uid . $username }{'template'} = 'Forum default';
            UserAccount( $username, 'update' );
        }
        while ( ( $curtemplate, $value ) = each %templateset ) {
            if ( $curtemplate eq ${ $uid . $username }{'template'} ) {
                $template = $curtemplate;
            }
        }
    }
</search for>

<replace>
    if (${ $uid . $username }{'template'} ne q{} || $yyCookies{'yabb2template'} ne q{} || $FORM{'template'} ne q{}) {
        while (($curtemplate, $value) = each(%templateset)) {
            if ($FORM{'template'} && $curtemplate eq $FORM{'template'}) {
                if ( $sessionvalid && !$iamguest ) {
                    ${ $uid . $username }{'template'} = $FORM{'template'};
                    UserAccount($username, 'update');
                }
                else {
                    if ($pathval eq q{}) { $pathval = qq~/~; }
                    $yySetCookies1 = write_cookie(
                        -name    => 'yabb2template',
                        -value   => $FORM{'template'},
                        -path    => $pathval,
                        -expires => "Sunday, 17-Jan-2038 00:00:00 GMT");
                }
                my $redir = $FORM{'redir'} ? "?$FORM{'redir'}" : $iamguest ? '?' : q{};
                $redir =~ s/search2/search/gxsm;
                $yySetLocation = qq~$scripturl$redir~;
                redirectexit();
            }
            elsif ($iamguest && $curtemplate eq $yyCookies{'yabb2template'}) { $template = $curtemplate; }
            elsif ($curtemplate eq ${ $uid . $username }{'template'}) { $template = $curtemplate; }
        }
    }
</replace>

<edit file>
Sources/Subs.pm
</edit file>

<search for>
    $yynavback .=
qq~$tabsep <span onclick="toTop(0)" class="cursor">$img_txt{'102'}</span> &nbsp; $tabsep~;
</search for>

<add after>

    if (!$temp_switcher_allowed || ($temp_switcher_allowed == 1 && !$iamguest)) {

    if ($templ_switcher) {
        $yystyleswitch = qq~$maintxt{'tmpchange'}&nbsp;~;
        $yytempswitcher = qq~
            <form name="styleswitcher" action="$scripturl" method="post">
            <input type="hidden" name="redir" value="$testenv" />
            <select name="template" onchange="submit()">
        ~;
        foreach my $curtemplate (sort{ $templateset{$a} cmp $templateset{$b} } keys %templateset) {
            $yytempswitcher .= qq~<option value="$curtemplate"~;
            if ( $template eq $curtemplate) { $yytempswitcher .= q~ selected="selected"~;}
            $yytempswitcher .= qq~>$curtemplate</option>\n~;
        }
        $yytempswitcher .= q~
            </select>
            </form>
        ~;
        }
    }
</add after>

<edit file>
Languages/English/Admin.lng
</edit file>

<search for>
1;
</search for>

<add before>
$admin_txt{'813a'} = 'Enable Style Switcher Dropdown Field?<br /><span class="small">If enabled, you have a option to quick select and changing the forum layout if other templates or css stylesheets available.</span>';
$admin_txt{'813b'} = 'Select the membergroups allowed to use the Style Switcher?</span>';

</add before>

<edit file>
Languages/English/Main.lng
</edit file>

<search for>
1;
</search for>

<add before>
$maintxt{'tmpchange'} = 'Change Template:';

</add before>

<edit file>
Templates/default/default.html
</edit file>

<search for>
        <table class="menutop" style="table-layout:fixed">
            <colgroup>
                <col style="width:auto" />
                <col style="width:250px" />
                <col style="width:auto" />
            </colgroup>
            <tr>
                <td class="small h_23px" style="padding-left:1%"><div id="yabbclock">{yabb time}</div></td>
                <td class="small">{yabb langChooser}</td>
                <td class="right vtop"><div class="yabb_searchbox">{yabb searchbox}</div>
                    <div class="yabb_rss">{yabb rss}</div>
                </td>
            </tr>
        </table>
</search for>

<replace>
        <table class="menutop" style="table-layout:fixed">
            <colgroup>
                <col style="width:auto" />
                <col style="width:32%" />
                <col style="width:250px" />
                <col style="width:auto" />
            </colgroup>
            <tr>
                <td class="small h_23px" style="padding-left:1%"><div id="yabbclock">{yabb time}</div></td>
                <td class="small center">{yabb styleswitch}{yabb tempswitcher}</td>
                <td class="small">{yabb langChooser}</td>
                <td class="right vtop"><div class="yabb_searchbox">{yabb searchbox}</div>
                    <div class="yabb_rss">{yabb rss}</div>
                </td>
            </tr>
        </table>
</replace>
