<?php
class folder_write extends myQuicty {

function __construct($page,$application) {
	parent::__construct();
	$this->page = $page;
	$this->form = $this->page->form;
	
	$this->application_path = $this->page->qt_application_root.'/'.$application['name'];
}

function make($folder_name) {
	umask(0);
	if(!file_exists($this->application_path.'/lib/Pages/'.$folder_name))
		mkdir($this->application_path.'/lib/Pages/'.$folder_name,0777);
	if(!file_exists($this->application_path.'/view/'.$folder_name))
		mkdir($this->application_path.'/view/'.$folder_name,0777);
}

function rename($folder_name) {
	if(is_dir($this->application_path.'/lib/Pages/'.$_POST['old_name']))
		rename($this->application_path.'/lib/Pages/'.$_POST['old_name'],
				$this->application_path.'/lib/Pages/'.$folder_name);
	if(is_dir($this->application_path.'/view/'.$_POST['old_name']))
		rename($this->application_path.'/view/'.$_POST['old_name'],
				$this->application_path.'/view/'.$folder_name);
}

function delete($folder_name) {
	if(is_dir($this->application_path.'/lib/Pages/'.$folder_name)) {
		foreach(glob($this->application_path.'/lib/Pages/'.$folder_name."/*") as $filename) {
			if(is_dir($filename)) {
				$subdir = array_pop(explode('/',$filename));
				$this->delete($folder_name.'/'.$subdir);
			} else {
				unlink($filename);
			}
		}
		rmdir($this->application_path.'/lib/Pages/'.$folder_name);
	}
	if(is_dir($this->application_path.'/view/'.$folder_name)) {
		foreach(glob($this->application_path.'/view/'.$folder_name."/*") as $filename) {
			if(is_dir($filename)) {
				$subdir = array_pop(explode('/',$filename));
				$this->delete($folder_name.'/'.$subdir);
			} else {
				unlink($filename);
			}
		}
		rmdir($this->application_path.'/view/'.$folder_name);
	}
}

} // end of folder_write class
?>