<commit_before><?php

class Backend extends MY_Controller {
    private $kring;

    public function index() {
        $this->determine_kring();

        $this->template->set('pageTitle', 'Backend');
        $this->template->load('layout', 'backend/index', array(
            'kring' => $this->kring
        ));
    }

    public function aanmelden() {
        $this->load->helper('auth_helper');
        $kringId = auth_user($this->input->get('sessionId'));

        if($kringId == -1) {
            show_error('Access disallowed', 403);
        }
        else {
            $this->load->library('session');
            $this->session->set_userdata('backend_kring_id', $kringId);
            redirect('/backend');
        }
    }

    public function instellingen() {
        $this->determine_kring();

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

        $settings = new KringSetting();
        $settings->get_by_kring_id($this->kring->id);
        
        // create a new record if necessary
        if($settings->kring_id != $this->kring->id) {
            $settings->kring_id = $this->kring_id;
        }

        $this->form_validation->set_rules('enable_gui', 'Website actief?', 'is_natural');
        $this->form_validation->set_rules('enable_api', 'API actief?', 'is_natural');

        if($this->form_validation->run() == false) {
            $this->template->set('pageTitle', 'Instellingen &ndash; Backend');
            $this->template->load('layout', 'backend/instellingen', array(
                'kring' => $this->kring,
                'settings' => $settings
            ));
        } else {
            $settings->enable_gui = (int)$this->input->post('enable_gui');
            $settings->enable_api = (int)$this->input->post('enable_api');
            $settings->isic = $this->input->post('isic');
            $settings->isic_text = $this->input->post('isic_text');
            $settings->confirmation_text = $this->input->post('confirmation_text');
            $settings->save();
            redirect('/backend');
        }
    }

    public function leden() {
        $this->determine_kring();
        $this->template->set('pageTitle', 'Leden &ndash; Backend');
        
        $action = $this->input->get('action');
        if(!$action || !in_array($action, array('browse', 'import', 'export'))) {
            $action = 'browse';
        }

        $members = new Member();
        $members->order_by('last_name ASC, first_name ASC')->get_by_kring_id($this->kring->id);

        $this->load->library('table');
        $this->table->set_heading(array('Naam', 'Voornaam', 'UGent nr.', 'FK nr.', 'Geregistreerd op'));
        
        $this->table->set_template(array(
            'table_open' => '<table cellspacing="0" class="datagrid">',
            'row_start' => '<tr class="rowOdd">',
            'row_alt_start' => '<tr class="rowEven">'
        ));

        foreach($members->all as $member) {
            $card = new AssociatedCard();
            $card->get_where(array(
                'member_id' => $member->id,
                'academic_year' => $this->config->item('academic_year')
            ));

            $this->table->add_row($this->input->xss_clean(array(
                htmlentities($member->last_name),
                htmlentities($member->first_name),
                htmlentities($member->ugent_nr), 
                (count($card->all) == 0) ? '&#8709;' : $card->card_id,
                $member->date_registered)
            ));
        }

        $this->template->load('layout', 'backend/leden', array(
            'kring' => $this->kring,
            'table' => $this->table
        ));
    }

    public function kaarten() {
        $this->determine_kring();<commit_msg>Add utility to find missing records for ISIC<commit_after><?php

class Backend extends MY_Controller {
    private $kring;

    public function index() {
        $this->determine_kring();

        $this->template->set('pageTitle', 'Backend');
        $this->template->load('layout', 'backend/index', array(
            'kring' => $this->kring
        ));
    }

    public function aanmelden() {
        $this->load->helper('auth_helper');
        $kringId = auth_user($this->input->get('sessionId'));

        if($kringId == -1) {
            show_error('Access disallowed', 403);
        }
        else {
            $this->load->library('session');
            $this->session->set_userdata('backend_kring_id', $kringId);
            redirect('/backend');
        }
    }

    public function instellingen() {
        $this->determine_kring();

        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

        $settings = new KringSetting();
        $settings->get_by_kring_id($this->kring->id);
        
        // create a new record if necessary
        if($settings->kring_id != $this->kring->id) {
            $settings->kring_id = $this->kring_id;
        }

        $this->form_validation->set_rules('enable_gui', 'Website actief?', 'is_natural');
        $this->form_validation->set_rules('enable_api', 'API actief?', 'is_natural');

        if($this->form_validation->run() == false) {
            $this->template->set('pageTitle', 'Instellingen &ndash; Backend');
            $this->template->load('layout', 'backend/instellingen', array(
                'kring' => $this->kring,
                'settings' => $settings
            ));
        } else {
            $settings->enable_gui = (int)$this->input->post('enable_gui');
            $settings->enable_api = (int)$this->input->post('enable_api');
            $settings->isic = $this->input->post('isic');
            $settings->isic_text = $this->input->post('isic_text');
            $settings->confirmation_text = $this->input->post('confirmation_text');
            $settings->save();
            redirect('/backend');
        }
    }

    public function leden() {
        $this->determine_kring();
        $this->template->set('pageTitle', 'Leden &ndash; Backend');
        
        $action = $this->input->get('action');
        if(!$action || !in_array($action, array('browse', 'import', 'export'))) {
            $action = 'browse';
        }

        $members = new Member();
        $members->order_by('last_name ASC, first_name ASC')->get_by_kring_id($this->kring->id);

        $this->load->library('table');
        $this->table->set_heading(array('Naam', 'Voornaam', 'UGent nr.', 'FK nr.', 'Geregistreerd op'));
        
        $this->table->set_template(array(
            'table_open' => '<table cellspacing="0" class="datagrid">',
            'row_start' => '<tr class="rowOdd">',
            'row_alt_start' => '<tr class="rowEven">'
        ));

        foreach($members->all as $member) {
            $card = new AssociatedCard();
            $card->get_where(array(
                'member_id' => $member->id,
                'academic_year' => $this->config->item('academic_year')
            ));

            $this->table->add_row($this->input->xss_clean(array(
                htmlentities($member->last_name),
                htmlentities($member->first_name),
                htmlentities($member->ugent_nr), 
                (count($card->all) == 0) ? '&#8709;' : $card->card_id,
                $member->date_registered)
            ));
        }

        $this->template->load('layout', 'backend/leden', array(
            'kring' => $this->kring,
            'table' => $this->table
        ));
    }
    
   public function find_missing_isic() {
	return false;
        $missing = file(APPPATH . 'missing');
	foreach($missing as $name) {
		$name = trim($name, "\n");
		$result = $this->db->query('SELECT m.first_name, m.last_name, ac.card_id, m.email FROM members m INNER JOIN associated_cards ac ON ac.member_id = m.id WHERE LOWER(CONCAT(first_name, \' \', last_name)) = ?', array(strtolower($name)))->row_array();
		echo sprintf("%s\t%s\t%s\n", $name, $result['card_id'], $result['email']);
	}
    }

    public function kaarten() {
        $this->determine_kring();
{'fraction_non_alphanumeric': 0.18393077873918418, 'fraction_numerical': 0.002472187886279357, 'mean_word_length': 2.263816054860831, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 210, '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': '1990496', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2432, 'n_words': 373}