<?php
class thread extends myQuicty {

function dispatch_index() {
	$this->caching = 0;// caching page flag: 0 = none; 1 = simple; 2 = each query;
	$this->cache_lifetime = 1800; // cache life time by seconds
	$cache_id = get_query_id(); // get uniqe id by query
	if(!$this->is_cached($this->current_template,$cache_id)) {
		// 話題の表示
		$this->subject['id'] = $_REQUEST['subject_id'];
		$SUBJECT = $this->new_data_set('subject');
		$table = $SUBJECT->select_table('where id='.$this->subject['id']);
		$this->assign('subject_view',$SUBJECT->display_table_value($table));
		// フォームの設定
		$form = $this->new_data_set('thread');
		$form->set_base_link_addr(quicty_base_url().'/thread/');
		$form->set_restart_link_addr(quicty_base_url().'/thread/');
		if(($this->QuictyStatus=='INSERT' or $this->QuictyStatus=='UPDATE' or $this->QuictyStatus=='DELETE')
			and $this->user['level'] < registerd_user) {
				$this->page['message'] = "投稿・更新は、ログインしないと、できません\n";
				$this->QuictyStatus='START';
		}
		$form->validate_and_freeze();
		$form->set_button_status('use_confirm',false);
		$form->bind_button_control();
		$result = $form->automatic_form_handler($condition);
		// 話題の「更新日時」の更新
		if($this->QuictyStatus=='INSERT' or $this->QuictyStatus=='UPDATE' or $this->QuictyStatus=='DELETE') {
			$update_datetime = parse_datetime(trim($result['thread']['entry_datetime'],"'"));
			$update_set = array('update_datetime'=>$update_datetime);
			$SUBJECT->update_table($update_set,'where id='.$this->subject['id']);
			redirect('/thread/?subject_id='.$this->subject['id']);
		}
		// 表示
		$this->site['name'] = 'スレッド';
		$this->assign('site',$this->site);
		$this->page['name'] = 'スレッド';
		$this->page['base_url'] = quicty_base_url();
		$this->assign_form('input_form',$form);
		$table = $form->select_table(' order by id');
		$this->assign('table_view',$form->display_table_value($table));
		$this->assign('page',$this->page);
		//-- End of dispatch_index
	}
	$result = $this->display($this->current_template,$cache_id);
	return $result;
}

} // end of thread class
?>