<?php
/**
 * Sitemapモジュールの管理
 */
require_once 'Zend/Controller/Action.php';

class Manage_SitemapController extends Zend_Controller_Action
{
    public function preDispatch()
    {
        global $Me;
        if ($Me->isAllowed('Manage_Site') == false) {
            $this->_redirect('/Manage/Login/');
        }
    }
    
    public function indexAction()
    {
        $this->configAction();
    }
    
    public function configAction()
    {
        global $db, $config;
        
        ob_start();
        
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $icon = intval($_POST['icon']);
            $module = intval($_POST['module']);
            $config['M_SITEMAP_ICON'] = $icon;
            $config['M_SITEMAP_MODULE'] = $module;
            $sql[] = "UPDATE Platy_Config set value='" . $config['M_SITEMAP_ICON'] . "' WHERE name='M_SITEMAP_ICON'";
            $sql[] = "UPDATE Platy_Config set value='" . $config['M_SITEMAP_MODULE'] . "' WHERE name='M_SITEMAP_MODULE'";
            for ($i = 0; $i < count($sql); $i++) {
                $db->query($sql[$i]);
            }
        }
        else {
            $icon = $config['M_SITEMAP_ICON'];
            $module = $config['M_SITEMAP_MODULE'];
        }
        
        echo '<h2>サイトマップの設定</h2>' . "\n";
        echo '<form method="post" action="">' . "<br />\n";
        echo '<table class="form_table">' . "\n";
        
        echo '<tr><th>アイコンを表示する</th>' . "\n";
        echo '<td>';

        echo '<input type="radio" name="icon" VALUE="1"';
        if ($icon == 1) { echo ' checked="true"'; }
        echo ' />表示する&nbsp;';
        echo '<input type="radio" name="icon" VALUE="0"';
        if ($icon == 0) { echo ' checked="true"'; }
        echo ' />表示しない';
        
        echo '</td></tr>';

        echo '<tr><th>モジュールを表示する</th>' . "\n";
        echo '<td>';
        
        echo '<input type="radio" name="module" VALUE="1"';
        if ($icon == 1) { echo ' checked="true"'; }
        echo ' />表示する&nbsp;';
        echo '<input type="radio" name="module" VALUE="0"';
        if ($icon == 0) { echo ' checked="true"'; }
        echo ' />表示しない';
        
        echo '</td></tr>';
        echo '<tr><th></th><td>';
        echo '<input type="submit" value="更新する" />' . "\n";
        echo '</td></tr></table>' . "\n";
        echo '</form>' . "\n";
        
        $contents = ob_get_contents();
        ob_end_clean();
        
        Zend_Loader::loadClass('Zend_View');
        $view = new Zend_View();
        $view->setScriptPath(APP_PATH . 'Manage/views');
        $view->contents = $contents;
        echo $view->render('page.php');
    }
    
    public function noRouteAction()
    {
        //$this->_redirect('/');
        echo "noRouteAction";
    }
}
?>