#!/usr/local/php/bin/php
<?php
/**
 *	Project:	Quicty: Quick application build environment depends on PEAR and Smarty
 *	File:		qt_new
 *
 *	@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_new
/**
 *	qt_new class
 *
 *	@author		Tomoyuki Negishi <tomoyu-n@zubapita.jp>
 *	@access		public
 *	@package	Quicty
 */
class qt_new 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%`;
			$delim = '\\';
		} else {
			$delim = '/';
		}
		echo "Your current dir is ".$_ENV['PWD']."\n";
		umask(0);
		make_dir('bin');
		make_dir('etc');
		make_dir('etc/conf');
		make_dir('etc/data_def');
		make_dir('etc/data_set');
		make_dir('etc/data_view');
		make_dir('etc/sql');
		make_dir('htdocs');
		make_dir('htdocs/css');
		make_dir('htdocs/img');
		make_dir('htdocs/js');
		make_dir('lib');
		make_dir('lib/Pages');
		make_dir('lib/Components');
		make_dir('lib/Plugin');
		make_dir('lib/smarty_plugins');
		make_dir('var');
		make_dir('var/compiled_view',0777);
		make_dir('var/rss_cache',0777);
		make_dir('var/smarty_cache',0777);
		make_dir('view');
		make_dir('view/includes');

		copy_files($_ENV['QUICTY_MOD'].'/bin','bin');
		copy_files($_ENV['QUICTY_MOD'].'/etc/conf','etc/conf');
		copy_files($_ENV['QUICTY_MOD'].'/etc/data_def','etc/data_def');
		copy_files($_ENV['QUICTY_MOD'].'/etc/data_set','etc/data_set');
		copy_files($_ENV['QUICTY_MOD'].'/etc/data_view','etc/data_view');
		copy_files($_ENV['QUICTY_MOD'].'/etc/sql','etc/sql',true);
		copy_files($_ENV['QUICTY_MOD'].'/htdocs','htdocs');
		copy_files($_ENV['QUICTY_MOD'].'/htdocs/css','htdocs/css');
		copy_files($_ENV['QUICTY_MOD'].'/htdocs/img','htdocs/img');
		copy_files($_ENV['QUICTY_MOD'].'/htdocs/js','htdocs/js');
		copy_files($_ENV['QUICTY_MOD'].'/lib','lib');
		copy_files($_ENV['QUICTY_MOD'].'/lib/Pages/index.class.php','lib/Pages');
		copy_files($_ENV['QUICTY_MOD'].'/lib/Plugin','lib/Plugin');
		copy_files($_ENV['QUICTY_MOD'].'/lib/smarty_plugins','lib/smarty_plugins');
		copy_files($_ENV['QUICTY_MOD'].'/view','view');
		copy_files($_ENV['QUICTY_MOD'].'/view/includes','view/includes');

		if($_ENV['windir'] or !confirm_tty("Do you use '.htaccess'? [y/n] :",$override=true)) {
			echo "\ndone.\n";
			exit;
		}
		copy_files('etc/conf/.htaccess','htdocs');
		$pwd_array = explode($delim,$_ENV['PWD']);
		$PWD = array_pop($pwd_array);
		$PWD = array_pop($pwd_array).'/'.$PWD;
		$this->assign('PWD',$PWD);
		$this->compile_dir = '/tmp/quicty';
		umask(0);
		if(!file_exists($this->compile_dir)) mkdir($this->compile_dir);
		$this->template_dir = 'htdocs';
		$contents = $this->fetch('.htaccess');
		file_write_contents('htdocs/.htaccess',$contents);
		echo "Copy from 'etc/conf/.htaccess' to 'htdocs/.htaccess'\n";
		echo "\ndone.\n";
	}
} // end of class qt_new
// }}}

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

?>
