<?php
class ProductOptionsCategoriesController extends AppController {

	var $name = 'ProductOptionsCategories';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->ProductOptionsCategory->recursive = 0;
		$this->set('productOptionsCategories', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ProductOptionsCategory.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('productOptionsCategory', $this->ProductOptionsCategory->read(null, $id));
	}

	function add($id = null) {
		
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ProductOptionsCategory', true));
			$this->redirect(array('action'=>'index'));
		}


		if (!empty($this->data)) {
			$this->ProductOptionsCategory->create();
			if ($this->ProductOptionsCategory->save($this->data)) {
				$productid = $this->data['ProductOptionsCategory']['product_id'];
				$this->Session->setFlash(__('The ProductOptionsCategory has been saved', true));
				$this->redirect(array('controller'=>'products', 'action'=>'view', $productid));
			} else {
				$this->Session->setFlash(__('The ProductOptionsCategory could not be saved. Please, try again.', true));
			}
		}
		$product = $this->ProductOptionsCategory->Product->find('first', array('conditions'=> array('Product.id' => $id), 'recursive' => false));
		
		$this->set(compact('product'));
	}

	function edit($id = null) {
		
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ProductOptionsCategory', true));
			$this->redirect(array('action'=>'index'));
		}


		if (!empty($this->data)) {
			if ($this->ProductOptionsCategory->save($this->data)) {
				$this->Session->setFlash(__('The ProductOptionsCategory has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The ProductOptionsCategory could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->ProductOptionsCategory->read(null, $id);
		}
		$products = $this->ProductOptionsCategory->Product->find('list');
		$this->set(compact('products'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ProductOptionsCategory', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->ProductOptionsCategory->del($id)) {
			$this->Session->setFlash(__('ProductOptionsCategory deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>
