<?php
class SitesController extends AppController {

  var $name = 'Sites';
  var $helpers = array('Html', 'Form', 'Tree', 'ApCategoryList');
  var $uses = array('Category');

  function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('index');
  }

  function index() {
    $this->Category->recursive = -1;
    if ($root_category = $this->Category->findByParent_Id('0')) {
      $this->pageTitle = $root_category['Category']['title'];
      $this->set('heading_title', $root_category['Category']['title']);
      $this->set('meta_description', $root_category['Category']['meta_description']);
      $this->set('meta_keywords', $root_category['Category']['meta_keywords']);
      $this->set('current', $root_category);
      $conditions = 'parent_id = ' . $root_category['Category']['id'];
      $cTree = $this->Category->find('all', array('conditions' => $conditions, 'order' => 'lft ASC', 'recursive' => -1));
      $this->set('cTree', $cTree);
      $category = $this->Category->find('all', array('order' => 'lft ASC', 'recursive' => -1));
      $this->set('category', $category);
    } else {
      $this->redirect(array('controller' => 'users', 'action' => 'admin_login'));
    }
  }

  function admin_index() {
    $this->pageTitle = '管理画面：メインメニュー';
    $this->layout = 'admin';
    if (!$this->Category->findByParent_Id('0')) {
      $this->redirect(array('controller' => 'categories', 'action' => 'admin_init'));
    }
  }

}
?>