<commit_before><?php
class GroupC extends Controller {
	protected $_default_site = 'index';
	public function index($params) {
		$this->_access_type('html');
		global $session;
		if($session == null) {
			Message::add_error('Du måste vara inloggad först.');
			URL::redirect('');
		}
		$this->_register('groups', Group::selection(array(
			'@order' => 'name',
		)));
		$this->_display('index');
		new LayoutC('html');
	}

	public function edit($params) {
		$this->_access_type('html');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			URL::redirect('');
		}
		$group = Group::from_id(array_shift($params));
		if($group == null) {
			Message::add_error("Gruppen du försöker redigera finns inte");
			URL::redirect('/Group/index');
		}
		$this->_register('group', $group);
		$this->_display('edit');
		new LayoutC('html');
	}

	public function create($params) {
		$this->_access_type('html');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			Message::add_error("Du har inte access att skapa nya grupper");
			URL::redirect('');
		}
		$this->_display('create');
		new LayoutC('html');
	}

	public function make($params) {
		$this->_access_type('script');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			Message::add_error("Du har inte access att skapa nya grupper");
			URL::redirect('');
		}
		try{
			$access = new Access();
			$access->name = 'Grant "'.ClientData::post('name').'"';
			$access->code_name=rand();
			$access->commit();
			$setting = new Group();
			$setting->name = ClientData::post('name');
			$setting->access_id = $access->id;
			$setting->commit();
			$access->code_name = "grant_{$setting->id}";
			$access->commit();
			URL::redirect('/Group/index');
		} catch(Exception $e) {
			Message::add_error($e->getMessage());
			URL::redirect('/Group/Create');
		}
	}

	public function modify($params) {
		$this->_access_type('script');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			Message::add_error("Du har inte access att redigera grupper");
			URL::redirect('');
		}
		$group = Group::from_id(ClientData::post('group_id'));
		if(!$group) {
			Message::add_error("Gruppen du försöker redigera finns inte");
			URL::redirect('/Group/index');
		}
		try {
			$group->name= ClientData::post('name');
			$access = $groupp->Access;
			$access->name = "Grant \"{$group->name}\"";
			$group->commit();
			$access->commit();
			Message::add_notice("Gruppen updaterad");
			URL::redirect('/Group/index');
		} catch(Exception $e) {
			Message::add_error($e);
			URL::redirect();
		}
	}<commit_msg>Fixing Group/edit bug<commit_after><?php
class GroupC extends Controller {
	protected $_default_site = 'index';
	public function index($params) {
		$this->_access_type('html');
		global $session;
		if($session == null) {
			Message::add_error('Du måste vara inloggad först.');
			URL::redirect('');
		}
		$this->_register('groups', Group::selection(array(
			'@order' => 'name',
		)));
		$this->_display('index');
		new LayoutC('html');
	}

	public function edit($params) {
		$this->_access_type('html');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			URL::redirect('');
		}
		$group = Group::from_id(array_shift($params));
		if($group == null) {
			Message::add_error("Gruppen du försöker redigera finns inte");
			URL::redirect('/Group/index');
		}
		$this->_register('group', $group);
		$this->_display('edit');
		new LayoutC('html');
	}

	public function create($params) {
		$this->_access_type('html');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			Message::add_error("Du har inte access att skapa nya grupper");
			URL::redirect('');
		}
		$this->_display('create');
		new LayoutC('html');
	}

	public function make($params) {
		$this->_access_type('script');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			Message::add_error("Du har inte access att skapa nya grupper");
			URL::redirect('');
		}
		try{
			$access = new Access();
			$access->name = 'Grant "'.ClientData::post('name').'"';
			$access->code_name=rand();
			$access->commit();
			$setting = new Group();
			$setting->name = ClientData::post('name');
			$setting->access_id = $access->id;
			$setting->commit();
			$access->code_name = "grant_{$setting->id}";
			$access->commit();
			URL::redirect('/Group/index');
		} catch(Exception $e) {
			Message::add_error($e->getMessage());
			URL::redirect('/Group/Create');
		}
	}

	public function modify($params) {
		$this->_access_type('script');
		global $current_user;
		if($current_user == null || !$current_user->has_access('edit_group')) {
			Message::add_error("Du har inte access att redigera grupper");
			URL::redirect('');
		}
		$group = Group::from_id(array_shift($params));
		if(!$group) {
			Message::add_error("Gruppen du försöker redigera finns inte");
			URL::redirect('/Group/index');
		}
		try {
			$group->name= ClientData::post('name');
			$access = $group->Access;
			$access->name = "Grant \"{$group->name}\"";
			$group->commit();
			$access->commit();
			Message::add_notice("Gruppen updaterad");
			URL::redirect('/Group/index');
		} catch(Exception $e) {
			Message::add_error($e);
			URL::redirect();
		}
	}
{'fraction_non_alphanumeric': 0.207404678578007, 'fraction_numerical': 0.0, 'mean_word_length': 4.776595744680851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6472082', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1823, 'n_words': 328}