<?php
class page_form_options extends myQuicty {

function __construct($page) {
	parent::__construct();
	$this->page = $page;
	$this->form = $this->page->form;
}

function check_uniq($data) {
	$id = $_REQUEST[$this->id_column];
	$data = strtolower($data);
	if($id) {
		$condition = "WHERE id=$id AND name='$data' AND application_id=".$this->page->application['id'];
		if($this->page->folder['id']) {
			$condition .= ' AND folder_id='.$this->page->folder['id'];
		}
		$num = $this->form->count_rows($condition);
		if($num==1 or $num==0) {
			$result = true;
		} else {
			$result = false;
		}
	} else {
		$condition = "WHERE name='$data' AND application_id=".$this->page->application['id'];
		if($this->page->folder['id']) {
			$condition .= ' AND folder_id='.$this->page->folder['id'];
		}
		$num = $this->form->count_rows($condition);
		if($num==0) {
			$result = true;
		} else {
			$result = false;
		}
	}
	return $result;
}


function set_form_options() {
	$this->form->set_base_link_addr(quicty_base_url().'/page/');
	$this->form->set_restart_link_addr(quicty_base_url().'/page/');
	$this->form->set_button_status('use_confirm',false);
	$this->form->registerRule('check_uniq','callback','check_uniq',$this);
	$this->form->addRule('name','そのページはフォルダ内にすでに存在します。','check_uniq',NULL,'server');
}

function set_form_filters() {
	$this->form->applyFilter('_ALL_','trim');
}

} // end of class page_form_options
?>