<commit_before><?php

class Tag extends Controller {

	function Tag()
	{
		parent::Controller();
		return;
	}
	
	function index()
	{
		$this->load->model('Tag_model');
		$this->template->set('page_title', 'Tags');
		$this->template->set('nav_links', array('tag/add' => 'New Tag'));
		$this->template->load('template', 'tag/index');
		return;
	}

	function add()
	{
		$this->template->set('page_title', 'New Tag');

		/* Check access */
		if ( ! check_access('create tag'))
		{
			$this->messages->add('Permission denied.', 'error');
			redirect('tag');
			return;
		}

		/* Check for account lock */
		if ($this->config->item('account_locked') == 1)
		{
			$this->messages->add('Account is locked.', 'error');
			redirect('tag');
			return;
		}

		/* Colorpicker JS and CSS */
		$this->template->set('add_css', array(
			"plugins/colorpicker/css/colorpicker.css",
		));

		$this->template->set('add_javascript', array(
			"plugins/colorpicker/js/colorpicker.js",
			"plugins/colorpicker/js/eye.js",
			"plugins/colorpicker/js/utils.js",
			"plugins/colorpicker/js/layout.js",
			"plugins/colorpicker/js/startup.js",
		));

		/* Form fields */
		$data['tag_title'] = array(
			'name' => 'tag_title',
			'id' => 'tag_title',
			'maxlength' => '15',
			'size' => '15',
			'value' => '',
		);
		$data['tag_color'] = array(
			'name' => 'tag_color',
			'id' => 'tag_color',
			'maxlength' => '6',
			'size' => '6',
			'value' => '',
		);
		$data['tag_background'] = array(
			'name' => 'tag_background',
			'id' => 'tag_background',
			'maxlength' => '6',
			'size' => '6',
			'value' => '',
		);

		/* Form validations */
		$this->form_validation->set_rules('tag_title', 'Tag title', 'trim|required|min_length[2]|max_length[15]|unique[tags.title]');
		$this->form_validation->set_rules('tag_color', 'Tag color', 'trim|required|exact_length[6]|is_hex');
		$this->form_validation->set_rules('tag_background', 'Background color', 'trim|required|exact_length[6]|is_hex');

		/* Re-populating form */
		if ($_POST)
		{
			$data['tag_title']['value'] = $this->input->post('tag_title', TRUE);
			$data['tag_color']['value'] = $this->input->post('tag_color', TRUE);
			$data['tag_background']['value'] = $this->input->post('tag_background', TRUE);
		}

		if ($this->form_validation->run() == FALSE)
		{
			$this->messages->add(validation_errors(), 'error');
			$this->template->load('template', 'tag/add', $data);
			return;
		}
		else
		{
			$data_tag_title = $this->input->post('tag_title', TRUE);
			$data_tag_color = $this->input->post('tag_color', TRUE);
			$data_tag_color = strtoupper($data_tag_color);
			$data_tag_background = $this->input->post('tag_background', TRUE);
			$data_tag_background = strtoupper($data_tag_background);

			$this->db->trans_start();
			$insert_data = array(
				'title' => $data_tag_title,
				'color' => $data_tag_color,
				'background' => $data_tag_background,
			);
			if ( ! $this->db->insert('tags', $insert_data))
			{
				$this->db->trans_rollback();
				$this->messages->add('Error addding ' . $data_tag_title . ' - Tag.', 'error');
				$this->logger->write_message("error", "Error adding tag named " . $data_tag_title);
				$this->template->load('template', 'tag/add', $data);
				return;
			} else {
				$this->db->trans_complete();
				$this->messages->add('Added ' . $data_tag_title . ' - Tag.', 'success');
				$this->logger->write_message("success", "Added tag named " . $data_tag_title);
				redirect('tag');
				return;
			}
		}
		return;

	}

	function edit($id = 0)
	{
		$this->template->set('page_title', 'Edit Tag');

		/* Check access */
		if ( ! check_access('edit tag'))
		{
			$this->messages->add('Permission denied.', 'error');
			redirect('tag');
			return;
		}

		/* Check for account lock */
		if ($this->config->item('account_locked') == 1)
		{
			$this->messages->add('Account is locked.', 'error');
			redirect('tag');
			return;
		}

		/* Colorpicker JS and CSS */
		$this->template->set('add_css', array(
			"plugins/colorpicker/css/colorpicker.css",
		));

		$this->template->set('add_javascript', array(
			"plugins/colorpicker/js/colorpicker.js",
			"plugins/colorpicker/js/eye.js",
			"plugins/colorpicker/js/utils.js",
			"plugins/colorpicker/js/layout.js",
			"plugins/colorpicker/js/startup.js",
		));

		/* Checking for valid data */
		$id = $this->input->xss_clean($id);
		$id = (int)$id;
		if ($id < 1) {
			$this->messages->add('Invalid Tag.', 'error');
			redirect('tag');
			return;
		}

		/* Loading current group */
		$tag_data_q = $this->db->query("SELECT * FROM tags WHERE id = ?", array($id));
		if ($tag_data_q->num_rows() < 1)
		{
			$this->messages->add('Invalid Tag.', 'error');
			redirect('tag');
			return;
		}
		$tag_data = $tag_data_q->row();

		/* Form fields */
		$data['tag_title'] = array(
			'name' => 'tag_title',
			'id' => 'tag_title',
			'maxlength' => '15',
			'size' => '15',
			'value' => $tag_data->title,
		);
		$data['tag_color'] = array(
			'name' => 'tag_color',
			'id' => 'tag_color',
			'maxlength' => '6',
			'size' => '6',
			'value' => $tag_data->color,
		);
		$data['tag_background'] = array(
			'name' => 'tag_background',
			'id' => 'tag_background',
			'maxlength' => '6',
			'size' => '6',
			'value' => $tag_data->background,
		);<commit_msg>Converted pending tag controller to active records<commit_after><?php

class Tag extends Controller {

	function Tag()
	{
		parent::Controller();
		return;
	}
	
	function index()
	{
		$this->load->model('Tag_model');
		$this->template->set('page_title', 'Tags');
		$this->template->set('nav_links', array('tag/add' => 'New Tag'));
		$this->template->load('template', 'tag/index');
		return;
	}

	function add()
	{
		$this->template->set('page_title', 'New Tag');

		/* Check access */
		if ( ! check_access('create tag'))
		{
			$this->messages->add('Permission denied.', 'error');
			redirect('tag');
			return;
		}

		/* Check for account lock */
		if ($this->config->item('account_locked') == 1)
		{
			$this->messages->add('Account is locked.', 'error');
			redirect('tag');
			return;
		}

		/* Colorpicker JS and CSS */
		$this->template->set('add_css', array(
			"plugins/colorpicker/css/colorpicker.css",
		));

		$this->template->set('add_javascript', array(
			"plugins/colorpicker/js/colorpicker.js",
			"plugins/colorpicker/js/eye.js",
			"plugins/colorpicker/js/utils.js",
			"plugins/colorpicker/js/layout.js",
			"plugins/colorpicker/js/startup.js",
		));

		/* Form fields */
		$data['tag_title'] = array(
			'name' => 'tag_title',
			'id' => 'tag_title',
			'maxlength' => '15',
			'size' => '15',
			'value' => '',
		);
		$data['tag_color'] = array(
			'name' => 'tag_color',
			'id' => 'tag_color',
			'maxlength' => '6',
			'size' => '6',
			'value' => '',
		);
		$data['tag_background'] = array(
			'name' => 'tag_background',
			'id' => 'tag_background',
			'maxlength' => '6',
			'size' => '6',
			'value' => '',
		);

		/* Form validations */
		$this->form_validation->set_rules('tag_title', 'Tag title', 'trim|required|min_length[2]|max_length[15]|unique[tags.title]');
		$this->form_validation->set_rules('tag_color', 'Tag color', 'trim|required|exact_length[6]|is_hex');
		$this->form_validation->set_rules('tag_background', 'Background color', 'trim|required|exact_length[6]|is_hex');

		/* Re-populating form */
		if ($_POST)
		{
			$data['tag_title']['value'] = $this->input->post('tag_title', TRUE);
			$data['tag_color']['value'] = $this->input->post('tag_color', TRUE);
			$data['tag_background']['value'] = $this->input->post('tag_background', TRUE);
		}

		if ($this->form_validation->run() == FALSE)
		{
			$this->messages->add(validation_errors(), 'error');
			$this->template->load('template', 'tag/add', $data);
			return;
		}
		else
		{
			$data_tag_title = $this->input->post('tag_title', TRUE);
			$data_tag_color = $this->input->post('tag_color', TRUE);
			$data_tag_color = strtoupper($data_tag_color);
			$data_tag_background = $this->input->post('tag_background', TRUE);
			$data_tag_background = strtoupper($data_tag_background);

			$this->db->trans_start();
			$insert_data = array(
				'title' => $data_tag_title,
				'color' => $data_tag_color,
				'background' => $data_tag_background,
			);
			if ( ! $this->db->insert('tags', $insert_data))
			{
				$this->db->trans_rollback();
				$this->messages->add('Error addding ' . $data_tag_title . ' - Tag.', 'error');
				$this->logger->write_message("error", "Error adding tag named " . $data_tag_title);
				$this->template->load('template', 'tag/add', $data);
				return;
			} else {
				$this->db->trans_complete();
				$this->messages->add('Added ' . $data_tag_title . ' - Tag.', 'success');
				$this->logger->write_message("success", "Added tag named " . $data_tag_title);
				redirect('tag');
				return;
			}
		}
		return;

	}

	function edit($id = 0)
	{
		$this->template->set('page_title', 'Edit Tag');

		/* Check access */
		if ( ! check_access('edit tag'))
		{
			$this->messages->add('Permission denied.', 'error');
			redirect('tag');
			return;
		}

		/* Check for account lock */
		if ($this->config->item('account_locked') == 1)
		{
			$this->messages->add('Account is locked.', 'error');
			redirect('tag');
			return;
		}

		/* Colorpicker JS and CSS */
		$this->template->set('add_css', array(
			"plugins/colorpicker/css/colorpicker.css",
		));

		$this->template->set('add_javascript', array(
			"plugins/colorpicker/js/colorpicker.js",
			"plugins/colorpicker/js/eye.js",
			"plugins/colorpicker/js/utils.js",
			"plugins/colorpicker/js/layout.js",
			"plugins/colorpicker/js/startup.js",
		));

		/* Checking for valid data */
		$id = $this->input->xss_clean($id);
		$id = (int)$id;
		if ($id < 1) {
			$this->messages->add('Invalid Tag.', 'error');
			redirect('tag');
			return;
		}

		/* Loading current group */
		$this->db->from('tags')->where('id', $id);
		$tag_data_q = $this->db->get();
		if ($tag_data_q->num_rows() < 1)
		{
			$this->messages->add('Invalid Tag.', 'error');
			redirect('tag');
			return;
		}
		$tag_data = $tag_data_q->row();

		/* Form fields */
		$data['tag_title'] = array(
			'name' => 'tag_title',
			'id' => 'tag_title',
			'maxlength' => '15',
			'size' => '15',
			'value' => $tag_data->title,
		);
		$data['tag_color'] = array(
			'name' => 'tag_color',
			'id' => 'tag_color',
			'maxlength' => '6',
			'size' => '6',
			'value' => $tag_data->color,
		);
		$data['tag_background'] = array(
			'name' => 'tag_background',
			'id' => 'tag_background',
			'maxlength' => '6',
			'size' => '6',
			'value' => $tag_data->background,
		);
{'fraction_non_alphanumeric': 0.2254762581745806, 'fraction_numerical': 0.004928442801630177, 'mean_word_length': 3.753153153153153, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 248, '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': '7044273', 'n_tokens_mistral': 4416, 'n_tokens_neox': 3802, 'n_words': 617}