<?php
class controller_theme extends controller
{
    ////////////////////////////////////////////////////////////////////////////
    // Construct and destruct functions.
    
    ////////////////////////////////////////////////////////////////////////////
    // Overload functions.

    ////////////////////////////////////////////////////////////////////////////
    // Interface functions.
    
    ////////////////////////////////////////////////////////////////////////////
    // Internal functions.
    
    protected function execute_index()
    {
        $data['themes'] = theme::get_list();
        $data['current'] = theme::get_current();
        $this->render('index.html', $data);
    }
    
    protected function execute_view($id)
    {
        $data['theme'] = theme::get($id);
        $this->render('view.html', $data);
    }
    
    protected function execute_current()
    {
        $data['theme'] = theme::get_current();
        $this->render('current.html', $data);
    }
    
    protected function execute_store()
    {
        $this->render('store.html');
    }
    
    protected function execute_apply($id)
    {
        $theme = theme::get($id);
        setting::delete_by_type('site.theme');
        setting::set('id', 'site.theme', $theme['id']);
        
        foreach ($theme['skin']['options'] as $option)
        {
            setting::set($option['name'], 'site.theme', $option['value'], $option['type'], $option['parameters']);
        }
        
        $this->redirect('theme/current/');
    }
}
