<?php 
class Defaultvalue_Controller extends Base_Controller{
	function __construct(){
		parent::__construct();
		$this->defval	=	new Default_Model();
	}
	function index(){
		$this->view	=	new View("default/list");
		$this->view->types	=	$this->defval->getDefVals()->result_array();
		$this->display();
	}
	function add(){
		if($this->input->post()){
			$default			=	$this->input->post("default");
			$default['enabled']	=	1;
			$this->defval->add($default);
			unset($_POST);
			$this->index();
		}
		else{
			$this->view		=	new View("default/form");
			$this->main->formAction="defaultvalue/add";
			$this->main->is_validator=true;
			$this->display();
		}
	}
	function delete($defaultid=0){
		if($this->input->post()){
			$ids		=	$this->input->post('select_id');
		}
		else{
			$ids[]		=	$defaultid;
		}
		$this->defval->delete($ids);
		unset($_POST);
		$this->index();
	}
	function edit($typeid=0){
		if($this->input->post()){
			$defaultid	=	$this->input->post("defaultid");
			$default	=	$this->input->post("default");
			$this->defval->UpDefault($defaultid,$default);
			unset($_POST);
			$this->index();
		}
		else{
			$this->view		=	new View("default/form");
			$this->main->formAction="defaultvalue/edit";
			$this->view->default	=	$this->defval->getDefVals($typeid)->current();
			$this->main->is_validator=true;
			$this->display();
		}
	}
	
}