<commit_before><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Items extends CI_Controller {

    public function val_zero($z) {
        if ($z < 0.001) {
            $this->form_validation->set_message('val_zero', '{field} must be more than 0.');
            return FALSE;
        } else {
            return TRUE;
        }
    }

    public function index() {
        //echo "<pre>";print_r($this->session->username);die;

        $this->load->library('table');

        $this->load->model('item_model');
        $items = $this->item_model->get();

        $item_list = array();
        foreach ($items as $id => $item) {
            $item_list[] = array(
                $item->brand . " " . $item->name . " (" . $item->qty . " " . $item->unit . ")",
                anchor('items/view/' . $item->id, '<span class="glyphicon glyphicon-search"></span> View Prices', array(
                    'class' => 'btn btn-primary',
                ))
            );
        }

        $this->load->view('items', array(
            'item_list' => $item_list
        ));
    }

    public function add() {

        include '_checksession.php';

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

        $this->load->model('shop_model');
        $shops = $this->shop_model->get();

        $shop_dropdown = array();
        foreach ($shops as $id => $shop) {
            $shop_dropdown[$id] = $shop->name;
        }

        $this->form_validation->set_rules(array(
            array(
                'field' => 'brand',
                'label' => 'Brand',
                'rules' => ''
            ),
            array(
                'field' => 'name',
                'label' => 'Item Name',
                'rules' => 'required'
            ),
            array(
                'field' => 'price',
                'label' => 'Price',
                'rules' => 'required|numeric|callback_val_zero|max_length[6]'
            ),
            array(
                'field' => 'qty',
                'label' => 'Quantity',
                'rules' => 'required|integer|callback_val_zero|max_length[6]'
            ),
        ));

        $this->form_validation->set_error_delimiters('<div class="alert alert-danger">'
                . '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>', '</div>');

        $unit = [
            'pack' => 'pack',
            'piece' => 'piece',
            'L' => 'L',
            'mL' => 'mL',
            'g' => 'g',
            'kg' => 'kg',
            'mg' => 'mg',
            'lb' => 'lb',
            'oz' => 'oz',
        ];

        if (!$this->form_validation->run()) {
            $this->load->view('item_form', array(
                'shop_dropdown' => $shop_dropdown,
                'unit' => $unit,<commit_msg>Final Bug fix<commit_after><?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Items extends CI_Controller {

    public function val_zero($z) {
        if ($z < 0.001) {
            $this->form_validation->set_message('val_zero', '{field} must be more than 0.');
            return FALSE;
        } else {
            return TRUE;
        }
    }

    public function index() {
        //echo "<pre>";print_r($this->session->username);die;

        $this->load->library('table');

        $this->load->model('item_model');
        $items = $this->item_model->get();

        $item_list = array();
        foreach ($items as $id => $item) {
            $item_list[] = array(
                $item->brand . " " . $item->name . " (" . $item->qty . " " . $item->unit . ")",
                anchor('items/view/' . $item->id, '<span class="glyphicon glyphicon-search"></span> View Prices', array(
                    'class' => 'btn btn-primary',
                ))
            );
        }

        $this->load->view('items', array(
            'item_list' => $item_list
        ));
    }

    public function add() {

        include '_checksession.php';

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

        $this->load->model('shop_model');
        $shops = $this->shop_model->get();

        $shop_dropdown = array();
        foreach ($shops as $id => $shop) {
            $shop_dropdown[$id] = $shop->name;
        }

        $this->form_validation->set_rules(array(
            array(
                'field' => 'brand',
                'label' => 'Brand',
                'rules' => ''
            ),
            array(
                'field' => 'name',
                'label' => 'Item Name',
                'rules' => 'required'
            ),
            array(
                'field' => 'price',
                'label' => 'Price',
                'rules' => 'required|numeric|callback_val_zero|max_length[6]'
            ),
            array(
                'field' => 'qty',
                'label' => 'Quantity',
                'rules' => 'required|numeric|callback_val_zero|max_length[6]'
            ),
        ));

        $this->form_validation->set_error_delimiters('<div class="alert alert-danger">'
                . '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>', '</div>');

        $unit = [
            'pack' => 'pack',
            'piece' => 'piece',
            'L' => 'L',
            'mL' => 'mL',
            'g' => 'g',
            'kg' => 'kg',
            'mg' => 'mg',
            'lb' => 'lb',
            'oz' => 'oz',
        ];

        if (!$this->form_validation->run()) {
            $this->load->view('item_form', array(
                'shop_dropdown' => $shop_dropdown,
                'unit' => $unit,
{'fraction_non_alphanumeric': 0.18567918567918568, 'fraction_numerical': 0.002457002457002457, 'mean_word_length': 1.500658183413778, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 139, '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': '6417473', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1624, 'n_words': 303}