<?php
require_once DAO . 'CityDao.php';
require_once DAO . 'WardDao.php';
require_once DTO . 'AreaDto.php';
final class Area extends Action {
  private $dto;
  public function __construct() {
    $this->checkAccess();
    $this->dto = new AreaDto();
  }
  protected function getDto() {
    return $this->dto;
  }
  public function index() {
  }
  public function city() {
    header('Content-Type: application/json; charset=utf-8');
    $dao = new CityDao();
    $res = $dao->getByPrefectureId($this->dto->prefectureId);
    $result = array();
    while ($row = mysql_fetch_assoc($res)) {
      $result[] = '"' . $row['city_id'] . '":"' . $row['city_name'] . '"';
    }
    echo '{' . implode(',', $result) . '}';
    return new Direct();
  }
  public function ward() {
    header('Content-Type: application/json; charset=utf-8');
    $dao = new WardDao();
    $res = $dao->getByPrefectureCityId(array($this->dto->prefectureId, $this->dto->cityId));
    $result = array();
    while ($row = mysql_fetch_assoc($res)) {
      $result[] = '"' . $row['ward_id'] . '":"' . $row['ward_name'] . '"';
    }
    echo '{' . implode(',', $result) . '}';
    return new Direct();
  }
}
// EOF.
