<?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->set_pager();
		$this->assign_page_and_pathlist($this->W['_review_review_list']);
	}
	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->assign_page_and_pathlist($this->W['_review_review_display']);
	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->assign_page_and_pathlist($this->W['_review_review_add']);
	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->assign_page_and_pathlist($this->W['_review_review_edit']);
	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->assign_page_and_pathlist($this->W['_review_review_delete']);
	return $this->display($this->current_template);
}

function dispatch_error() {
	$this->page['message'] = $this->W['_review_login_error'];
	$this->assign_page_and_pathlist($this->W['_review_please_login']);
	return $this->display($this->current_template);
}

} // end of reviews class
?>