<?php
require_once 'spot_classes/_base.class.php';
class spot extends spot_base {

public function pre_dispatch_index() {
	parent::pre_dispatch_index();

	$dbpath = realpath('../var/sqlite/google_maps');
	$this->dsn = "sqlite:///$dbpath?mode=0666";

	if($_SERVER['SERVER_NAME']=='quicty.local') {
		$this->API_key = 'ABQIAAAAC436CRylt4eXoOKxyByBiBRBQE8rB7imLa7zJdMNnYqHlMIovBSIZs_tiVm4m8qF3dmjsROzw4E4_Q';
	} elseif($_SERVER['SERVER_NAME']=='other domain') {
		$this->API_key = 'other keys';
	}
}

function dispatch_index() {
	if(!$this->is_cached($this->current_template,$this->cache_id)) {
		require_once 'Quicty/lib/GoogleMap.class.php';
		$this->map = new GoogleMap($this->dsn,$this->API_key,'500px','400px',0);
		$this->assign_search_form();

		$list_table = $this->list_records('');
		if(is_array($list_table) and count($list_table)>0) {
			foreach($list_table as $spot) {
				$this->map->add_marker_by_address($spot['address'],$spot['name'],'');
			}
		} else {
			$center = '東京都新宿区西新宿二丁目8番1号';
			$this->map->add_marker_by_address($center,'東京都庁<br />');
		}

		$this->assign('table_view',$this->list->display_table_value($list_table));
		$this->assign('display_cmd','info');
		$this->page['pager'] = $this->list->get_pager_links();
		$this->page['name'] = 'スポットの一覧';
		$this->page = array_merge($this->page,$this->map->get_components());
		$this->assign('page',$this->page);
	}
	return $this->display($this->current_template,$this->cache_id);
}

function dispatch_info() {
	$this->assign_search_form();
	$result = $this->display_record();
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'スポットの表示';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_add() {
	$this->assign_search_form();
	$result = $this->display_record();
	if($this->QuictyStatus=='INSERT') {
		redirect('<!--{$folder_name}-->/spot/');
	}
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'スポットの追加';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_edit() {
	$this->assign_search_form();
	$result = $this->display_record();
	if($this->QuictyStatus=='UPDATE') {
		redirect('<!--{$folder_name}-->/spot/');
	}
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'スポットの編集';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_delete() {
	$this->assign_search_form();
	$result = $this->display_record();
	if($this->QuictyStatus=='DELETE') {
		redirect('<!--{$folder_name}-->/spot/');
	}
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'スポットの削除';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_batch_update() {
	$list_table = $this->batch_update();
	if($this->QuictyStatus=='UPDATE') {
		redirect('<!--{$folder_name}-->/spot/');
	}
	
	$base_url = quicty_base_url();
	$update_form['display_cmd'] = $base_url.'<!--{$folder_name}-->/spot/edit';
	//$update_form['conditions']['any_key'] = $_REQUEST['any_key'];
	$update_form['even_color'] = '#fee';	
	$this->assign_batch_form('table_view',$list_table,$max_column=1,$update_form);
	$navi = $this->list->get_pager_links();
	$this->assign('pager_navi',$navi['all']);
	$this->page['name'] = 'スポットの一括更新';
	$this->assign_page_and_pathlist();
	$this->assign('page',$this->page);
	return $this->display($this->current_template);
}

} // end of spot class
?>