<?php
require_once 'reviews_classes/_base.class.php';
class reviews extends reviews_base {

function set_items_info($items_id) {
	require_once 'items.class.php';
	$items = new items();
	$items->assign_search_form($this);
	$items->QuictyStatus = 'BROWSE';
	$items->display_record('id='.$items_id);
	$this->items = $items->items;
	$this->assign_form('items_info',$items->form);
}

function check_wrote($items_id) {
	$check = $this->select_row('reviews',"where items_id=$items_id and user_id=".$this->user['id']);
	if($check)
		return $check['id'];
	else
		return false;
}

//----------------------------
// dispatch point

function dispatch_index() {
	if(!$this->is_cached($this->current_template,$this->cache_id)) {
		require_once 'items.class.php';
		$items = new items();
		$items->assign_search_form($this);
		$list_table = $this->list_records('');

		$this->assign('table_view',$this->list->display_table_value($list_table));
		$this->assign('display_cmd','info');
		$this->page['pager'] = $this->list->get_pager_links();
		$this->page['name'] = 'レビューの一覧';
		$this->assign('page',$this->page);
	}
	return $this->display($this->current_template,$this->cache_id);
}

function dispatch_info() {
	$result = $this->display_record();
	$items_id = $this->reviews['items_id'];
	$this->set_items_info($items_id);
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'レビューの表示';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_add() {
	$items_id = $_REQUEST['items_id'];
	if($reviews_id=$this->check_wrote($items_id))
		redirect('/reviews/edit?id='.$reviews_id);

	$this->set_items_info($items_id);
	$result = $this->display_record();
	if($this->QuictyStatus=='INSERT') {
		redirect('<!--{$folder_name}-->/items/info?id='.$items_id);
	}
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'レビューの追加';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_edit() {
	$result = $this->display_record();
	$items_id = $this->reviews['items_id'];
	if($this->QuictyStatus=='UPDATE') {
		redirect('<!--{$folder_name}-->/items/info?id='.$items_id);
	} else {
		$this->set_items_info($items_id);
	}
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'レビューの編集';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_delete() {
	$result = $this->display_record();
	$items_id = $this->reviews['items_id'];
	if($this->QuictyStatus=='DELETE') {
		redirect('<!--{$folder_name}-->/items/info?id='.$_POST['items_id']);
	} else {
		$this->set_items_info($items_id);
	}
	
	$this->assign_form('input_form',$this->form);
	$this->page['name'] = 'レビューの削除';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

function dispatch_error() {
	$this->page['message'] = 'ログインしないと、書き込めません。';
	$this->page['name'] = 'ログインしてください';
	$this->assign_page_and_pathlist();
	return $this->display($this->current_template);
}

} // end of reviews class
?>