<?php  defined('C5_EXECUTE') or die("Access Denied.");

class DashboardUsersRegistrantGroupController extends Controller {
	
	public $helpers = array('concrete/interface', 'form');
	
	public function view() {
		$co = new Config();
		$co->setPackageObject(Package::getByHandle('registrant_group'));
		$gID = $co->get('REGISTRANT_GROUP_ID');
		$g = Group::getByID($gID);
		if($g instanceof Group) {
			$this->set('gName',$g->getGroupName());
			$this->set('gID', $g->getGroupID());
		}
	}
	
	public function updated() {
		$this->set('message', t('Setting saved.'));
		$this->view();
	}
	
	public function save_settings() { //In single_pages, do not prepend "action_" (unlike blocks)
	
		$valt = Loader::helper('validation/token');
		if (!$valt->validate('save_settings', $token)) {
			throw new Exception($valt->getErrorMessage());
		}
	
		$gID = $this->post('gID');
		$gID = empty($gID) ? 0 : $gID;
		
		$co = new Config();
		$co->setPackageObject(Package::getByHandle('registrant_group'));
		$co->save('REGISTRANT_GROUP_ID', $gID);
		
		header('Location: ' . View::url('/dashboard/users/registrant_group', 'updated'));
		exit;
	}
	
}
