<?php
$lib_dir = dirname(__FILE__);
$dir_path = explode(DIRECTORY_SEPARATOR,$lib_dir);
$dummy = array_pop($dir_path);
$dummy = array_pop($dir_path);
$QT_root_dir = implode('/',$dir_path);
ini_set('include_path', $QT_root_dir.PATH_SEPARATOR.$QT_root_dir.'/Quicty/phplib'.PATH_SEPARATOR.$lib_dir.PATH_SEPARATOR.ini_get('include_path'));
require_once 'Quicty/Quicty.php';

class myQuicty extends  Quicty {

public function pre_dispatch_index() {
	$this->site['name'] = $this->W['site_name'];
	$this->assign('site',$this->site);
	$this->global_nav = $this->set_global_nav();
	$this->assign('global_nav',$this->global_nav);
	$search = array('/','.html');
	$replace = array('-','');
	$page_id = str_replace($search,$replace,$this->Quicty['request_path']);
	$this->page['id'] = $page_id;
	$this->page['class'] = $this->Quicty['action'];
	$base_path = quicty_base_path();
	$this->page['base_url'] = $base_path;
	$this->assign('b',$base_path);
	$this->assign('g',$_GET);
	$this->assign('p',$_POST);
	$this->assign('q',$this->Quicty);
	$this->assign('r',$_REQUEST);
	$this->assign('s',$_SERVER);

	if(file_exists('../etc/conf/userauth.on')) {
		define('admin_user',10);
		define('registerd_user',1);
		define('guest_user',0);
		$this->assign('admin_user',admin_user);
		$this->assign('registerd_user',registerd_user);
		$this->assign('guest_user',guest_user);
		$auth = $this->new_auth_obj('auth.set.conf');
		$this->user = $auth->get_user_data();
		if($this->user['authorized']===false) {
			$this->user['handle'] = $this->W['guest'];
			$this->user['level'] = guest_user;
		}
		$this->assign('user',$this->user);
	}
	setcookie("base_path",$base_path);

	// prepare display debug monitor
	if(($this->C['debug_url'] AND isset($_GET['DEBUG'])) OR $this->C['debug_monitor']) {
		$this->autoload_filters['output'][] = 'omit_endtag4debug_monitor';
	}

	return true;
}

public function dispatch_index() {
	return $this->display($this->current_template);
}

public function post_dispatch_index() {
	if(($this->C['debug_url'] AND isset($_GET['DEBUG'])) OR $this->C['debug_monitor']) {
		$this->display_debug_monitor($_GET['DEBUG']);
	}
	return true;
}

public function set_global_nav() {
	//$global_nav['home'] = array('path'=>'/','name'=>'Home');
	$global_nav['menu1'] = array('path'=>'/menu1/','name'=>'Menu1');
	$global_nav['menu2'] = array('path'=>'/menu2/','name'=>'Menu2');
	$global_nav['menu3'] = array('path'=>'/menu3/','name'=>'Menu3');
	$global_nav['menu4'] = array('path'=>'/menu4/','name'=>'Menu4');
	$global_nav['menu5'] = array('path'=>'/menu5/','name'=>'Menu5');
	return $global_nav;
}

public function set_pager_option($perPage,$condition) {
	$pager_option = array(
		'perPage'=>$perPage,
		'condition'=>$condition,
		'prevImg'=>$this->W['prev'].$perPage.$this->W['records'],
		'nextImg'=>$this->W['next'].$perPage.$this->W['records'],
		'separator'=>"&nbsp;",
		'curPageLinkClassName'=>'current_page',
		'firstPageText'=>$this->W['first_page'],'firstPagePre'=>'','firstPagePost'=>'',
		'lastPageText'=>$this->W['last_page'],'lastPagePre'=>'','lastPagePost'=>'',
	);
	if(preg_match("/.*(index|list)([0-9]*?)\.html$/"
			,basename($_SERVER['PHP_SELF'])
			,$matches)
		) {
		$page_base = $matches[1];
		$pager_option['importQuery'] = FALSE;
		$pager_option['append'] = FALSE;
		if($_GET['keyword']) {
			$querys['keyword'] = $_GET['keyword'];
		}
		if($_GET['kind']) {
			$querys['kind'] = $_GET['kind'];
		}
		if(count($querys)>0) {
			$query_string = '?'.http_build_query($querys);
		}
		$pager_option['fileName'] = $page_base.'%d.html'.$query_string;
	}
	return $pager_option;
}


} // end of class myQuicty
?>