#!/usr/local/php/bin/php
<?php
/**
 *	Project:	Quicty: Quick application build environment depends on PEAR and Smarty
 *	File:		qt_template
 *
 *	@copyright	Tomoyuki Negishi and ZubaPitaTech, Inc.
 *	@author		Tomoyuki Negishi <tomoyu-n@zubapita.jp>
 *	@license	http://www.opensource.org/licenses/bsd-license.php The BSD License
 *	@package	Quicty
 *	@version	$Id:$
 */

require_once 'myQuicty.php';

// {{{ qt_template
/**
 *	qt_template class
 *
 *	@author		Tomoyuki Negishi <tomoyu-n@zubapita.jp>
 *	@access		public
 *	@package	Quicty
 */
class qt_template extends myQuicty {

	function dispatch_index() {
		if(!$_ENV['QUICTY_MOD']) die("Did not define enviroment var 'QUICTY_MOD'.\n");
		if($_ENV['windir']) $_ENV['PWD'] = `echo %CD%`;
		echo "Your current dir is "; print_r($_ENV['PWD']); echo "\n";
		$files = list_dir($_ENV['QUICTY_MOD'].'/templates');
		$template = $_SERVER['argv'][1];
		while(!$template or !file_exists($_ENV['QUICTY_MOD'].'/templates/'.$template)) {
			$i=1;
			foreach($files as $file_name) {
				echo "$i:$file_name\n";
				$i++;
			}
			$number = freadline("\n select template No. :");
			$template = $files[$number-1];
		}
		echo "set template'$template'\n";
		$temp_root = $_ENV['QUICTY_MOD'].'/templates/'.$template;
		$copy_dir = true;
		if(is_dir($temp_root.'/bin')) copy_files($temp_root.'/bin','bin',false,0744);
		if(is_dir($temp_root.'/etc/conf')) copy_files($temp_root.'/etc/conf','etc/conf');
		if(is_dir($temp_root.'/etc/data_def')) copy_files($temp_root.'/etc/data_def','etc/data_def');
		if(is_dir($temp_root.'/etc/data_set')) copy_files($temp_root.'/etc/data_set','etc/data_set');
		if(is_dir($temp_root.'/etc/data_view')) copy_files($temp_root.'/etc/data_view','etc/data_view');
		if(is_dir($temp_root.'/etc/sql')) copy_files($temp_root.'/etc/sql','etc/sql',$copy_dir);
		if(is_dir($temp_root.'/htdocs')) copy_files($temp_root.'/htdocs','htdocs');
		if(is_dir($temp_root.'/htdocs/css')) copy_files($temp_root.'/htdocs/css','htdocs/css');
		if(is_dir($temp_root.'/htdocs/img')) copy_files($temp_root.'/htdocs/img','htdocs/img');
		if(is_dir($temp_root.'/htdocs/js')) copy_files($temp_root.'/htdocs/js','htdocs/js');
		if(is_dir($temp_root.'/lib')) copy_files($temp_root.'/lib','lib');
		if(is_dir($temp_root.'/lib/Pages')) copy_files($temp_root.'/lib/Pages','lib/Pages',$copy_dir);
		if(is_dir($temp_root.'/lib/Plugin')) copy_files($temp_root.'/lib/Plugin','lib/Plugin');
		if(is_dir($temp_root.'/lib/smarty_plugins')) copy_files($temp_root.'/lib/smarty_plugins','lib/smarty_plugins');
		if(is_dir($temp_root.'/view')) copy_files($temp_root.'/view','view',$copy_dir);
		if(is_dir($temp_root.'/view/includes')) copy_files($temp_root.'/view/includes','view/includes');
		echo "\ndone.\n";
	}
} // end of class qt_template
// }}}

$quicty = new qt_template();
$quicty->dispatch_index();

?>
