<?php

$main_class = 'CookieBar';
class CookieBar extends Window
{
    public function get_vars()
    {
        $vars = parent::get_vars();

        $settings = Settings::getDefault();
        $vars['body']['data']['cookie_bar'] = isset($settings->cookie_bar) ? $settings->cookie_bar : null;

        return $vars;
    }

    public function handle()
    {
        $data = getVal('data');
        $submit = getVal('Submit');
        if (!empty($data) && !empty($submit)) {
            $settings = Settings::getDefault();
            $settings->loadFromArray($data);
            $saved = $settings->saveToDB();
            if ($saved) {
                $this->returnOK();
            } else {
                $this->returnError('Chyba při ukládání');
            }
        }

        parent::handle();
    }

    public function hasRights($name = null)
    {
        switch ($name) {
            case self::RIGHT_DUPLICATE:
                return false;
                break;
            default:
                return parent::hasRights($name);
        }
    }
}
