/home/coolpkct/www/websites/cake3.cool.rocks/admin/commands/themeselect.php
<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2013, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>');
$sep = DIRECTORY_SEPARATOR;
require_once "commands{$sep}command.php" ;
require_once "classes{$sep}themeselectscreen.php";
require_once "classes{$sep}pageset.php";
require_once "classes{$sep}themeset.php";
 
/**
 * Command - Choose theme
 *
 * @package Showkase
 */
class ThemeSelect extends Command
{
    function doExecute( Request $request )
    {
        unset ($_SESSION['pageIndex']);
        $context = array('token' => $request->newToken());
        $themeSet = new ThemeSet();
        $themeName = $themeSet->getCurrentThemeName();
        $oldTheme = $themeName;
        if ($request->propertyIsSet('newtheme')) {
            try {
                if (!$request->validate()) {
                    throw new Exception('re-submission or remote submission is not allowed.');
                }
                $themeName = $request->getProperty('newtheme');
                $themeSet->saveCurrentThemeName($themeName);
                $themeSet = new ThemeSet();
                $pageSet = new PageSet();
                $publishPrompt = count($pageSet->getPagesData()) == 0
                    ? ''
                    : ' Republish to see changes.';
                $pageSet->setPagesPref('publishing', 'unpublished');
                $pageSet->savePagesPrefs();
                $pageSet->hideUnsupportedPageTypes($themeSet->getPageTypes());
                $pageSet->savePagesData();
                Board::addMessage('Current theme set to '.$themeSet->getThemeDisplayName($themeName).'.'.$publishPrompt);
            } catch (Exception $e) {
                //problems with some page(s) in new theme
                $themeName = $oldTheme;
                Board::addExceptionMessage($e);
            }
        }
        $context['theme'] = $themeName;
        $context['themeSet'] = $themeSet;
        $screen = new ThemeSelectScreen('Showkase &ndash; themes', 'themeselect', 'site themeselect');
        print $screen->getHtml($context);
    }
}