<?php
/*
 * $Id: fuzzylink.inc.php,v 1.1 2005/02/26 07:16:20 youka Exp $
 */

 
class Cmd_fuzzylink
{
	public static function getinstance()
	{
		return new Cmd_fuzzylink;
	}
	
	
	function run()
	{
		$get = KinoWiki::getinstance()->getGET();
		if(isset($get['key']) && $get['key'] != ''){
			return $this->show($get['key']);
		}
		else if(isset($get['param']) && $get['param'] == 'restruct'){
			return $this->restruct();
		}
		else{
			throw new CmdException('パラメータが足りません。', 'fuzzylink');
		}
	}

	
	protected function show($key)
	{
		$list = FuzzyLink::getinstance()->getpagelist($key);
		if($list == array()){
			throw new CmdException("「{$key}」で引くことの出来るページがありません。", 'fuzzylink');
		}
		else if(count($list) == 1){
			redirect($list[0]);
		}
		
		$smarty = new CmdSmarty('fuzzylink');
		$smarty->assign('key', $key);
		foreach($list as $page){
			$smarty->append('pagelist', $page->getpagename());
		}
		$ret['body'] = $smarty->fetch('list.tpl.htm');
		$ret['title'] = 'あいまいリンク';
		return $ret;
	}
	
	
	protected function restruct()
	{
		FuzzyLink::getinstance()->restruct();
		$smarty = new CmdSmarty('fuzzylink');
		$ret['body'] = $smarty->fetch('restruct.tpl.htm');
		$ret['title'] = 'あいまいリンク';
		return $ret;
	}
}

?>