<commit_before><?php

/**
 * Controller_Admin_Core_Base class.
 * 
 * @extends Controller_Template
 * @package Pbadmin
 * @category Controller
 */
class Controller_Admin_Core_Base extends Controller_Template {
	public $template = "admin/template";
	private $controller_url;
	private $session;
	public $request;

	public function __construct($id = null)
	{
		parent::__construct($id);
		
		$this->request = Request::instance();		
		$this->session= Session::instance();
	}

	/**
	 * checks if a user is allowed to open the requested page
	 * 
	 * @access public
	 * @return void
	 */
	public function before()
	{
		parent::before();

		//Check user auth and role
		$action_name = Request::instance()->action;

		if (($this->auth_required == true && Auth::instance()->logged_in() === false)
			|| (is_array($this->secure_actions) && array_key_exists($action_name, $this->secure_actions) &&
				Auth::instance()->logged_in($this->secure_actions[$action_name]) == false)) {
			if (Auth::instance()->logged_in()) {
				Message::instance()->error(ucfirst(__('access denied')));
				Request::instance()->redirect('admin/main/');
			} else {
				Message::instance()->error(ucfirst(__('access denied')));
				Request::instance()->redirect('admin/main/login');
			}
		} else {
			$this->user = Auth::instance()->get_user();
		}

		$this->template->title = "Admin";
		$this->template->content = "";
		$this->template->scripts = array();
		
		$this->controller_url = Request::instance()->directory . "/" . Request::instance()->controller;
		
		if ( Auth::instance()->logged_in()) {
			$this->template->menu = View::factory('admin/menubar')->set("items", Kohana::config('admin.menu'));
		} else {
		 	$this->template->menu = "";
		 }
	}
	
	
	/**
	 * creates the list-view of a object
	 * 
	 * @access public
	 * @return void
	 */
	public function action_index()
	{
		$get = $_GET;
		$page =  (isset($get['page'])) ? (int) $get['page']: 1;
		$offset = (($page > 0 ) ? $page - 1 : 0) * 20;
		
		//converts $_GET['filter'] in an array
		$filter = array();
		if (isset($get['filter'])) {
			foreach ($get['filter'] as $field => $value) {
				if ($value) {
					$filter[$field] = $value;
				}
			}
		}

		$this->session->set('requested_url', $this->request->uri.'?'.http_build_query($get, '&'));
		$this->session->delete('post_data_' . $this->orm_name);

		//count total objects
		$count = (isset($this->base_object)) ? $this->base_object->reset(false) : ORM::factory($this->orm_name)->find((int) $id);
		foreach ($filter as $field => $value) {
			$count->and_where($field, 'like', '%' . $value . '%');
		}
		$count = $count->count_all();
		
		
		//display message if no objects found
		if ($count == 0) {
			$msg = strtolower(__('no :objects found',  array(':objects' => __($this->orm_name))) . ".");
			
			//display link 'clear filter'
			if (isset($get['filter'])) {			
				$msg .= "&nbsp;" . html::anchor(Request::instance()->directory .'/' . Request::instance()->controller, __('clear filter'));
			}
			Message::instance()->info($msg);
		}
		
		
		//pagination
		$pagination = new Pagination;
		$page_config = $pagination->config_group('admin');
		$page_config['total_items'] = $count;
		$pagination->setup($page_config);

		//pagination, check if a page exists
		if (!$pagination->valid_page($page) && $pagination->__get('total_pages') > 0) {
			$get['page'] = $pagination->__get('total_pages');
			Request::instance()->redirect($this->request->uri.'?'.http_build_query($get, '&'));
		}
		
		
		//collect the orm objects
		$objects = (isset($this->base_object)) ? $this->base_object->reset(false) : ORM::factory($this->orm_name)->find((int) $id);
		$objects
			->offset($offset)
			->limit(20);
		foreach ($filter as $field => $value) {
			$objects->and_where($field, 'like', '%' . $value . '%');
		}
		$objects = $objects->find_all();<commit_msg>fix bug with base_object in core/base/action_index()<commit_after><?php

/**
 * Controller_Admin_Core_Base class.
 * 
 * @extends Controller_Template
 * @package Pbadmin
 * @category Controller
 */
class Controller_Admin_Core_Base extends Controller_Template {
	public $template = "admin/template";
	private $controller_url;
	private $session;
	public $request;

	public function __construct($id = null)
	{
		parent::__construct($id);
		
		$this->request = Request::instance();		
		$this->session= Session::instance();
	}

	/**
	 * checks if a user is allowed to open the requested page
	 * 
	 * @access public
	 * @return void
	 */
	public function before()
	{
		parent::before();

		//Check user auth and role
		$action_name = Request::instance()->action;

		if (($this->auth_required == true && Auth::instance()->logged_in() === false)
			|| (is_array($this->secure_actions) && array_key_exists($action_name, $this->secure_actions) &&
				Auth::instance()->logged_in($this->secure_actions[$action_name]) == false)) {
			if (Auth::instance()->logged_in()) {
				Message::instance()->error(ucfirst(__('access denied')));
				Request::instance()->redirect('admin/main/');
			} else {
				Message::instance()->error(ucfirst(__('access denied')));
				Request::instance()->redirect('admin/main/login');
			}
		} else {
			$this->user = Auth::instance()->get_user();
		}

		$this->template->title = "Admin";
		$this->template->content = "";
		$this->template->scripts = array();
		
		$this->controller_url = Request::instance()->directory . "/" . Request::instance()->controller;
		
		if ( Auth::instance()->logged_in()) {
			$this->template->menu = View::factory('admin/menubar')->set("items", Kohana::config('admin.menu'));
		} else {
		 	$this->template->menu = "";
		 }
	}
	
	
	/**
	 * creates the list-view of a object
	 * 
	 * @access public
	 * @return void
	 */
	public function action_index()
	{
		$get = $_GET;
		$page =  (isset($get['page'])) ? (int) $get['page']: 1;
		$offset = (($page > 0 ) ? $page - 1 : 0) * 20;
		
		//converts $_GET['filter'] in an array
		$filter = array();
		if (isset($get['filter'])) {
			foreach ($get['filter'] as $field => $value) {
				if ($value) {
					$filter[$field] = $value;
				}
			}
		}

		$this->session->set('requested_url', $this->request->uri.'?'.http_build_query($get, '&'));
		$this->session->delete('post_data_' . $this->orm_name);

		//count total objects
		$count = (isset($this->base_object)) ? $this->base_object->reset(false) : ORM::factory($this->orm_name);
		foreach ($filter as $field => $value) {
			$count->and_where($field, 'like', '%' . $value . '%');
		}
		$count = $count->count_all();
		
		
		//display message if no objects found
		if ($count == 0) {
			$msg = strtolower(__('no :objects found',  array(':objects' => __($this->orm_name))) . ".");
			
			//display link 'clear filter'
			if (isset($get['filter'])) {			
				$msg .= "&nbsp;" . html::anchor(Request::instance()->directory .'/' . Request::instance()->controller, __('clear filter'));
			}
			Message::instance()->info($msg);
		}
		
		
		//pagination
		$pagination = new Pagination;
		$page_config = $pagination->config_group('admin');
		$page_config['total_items'] = $count;
		$pagination->setup($page_config);

		//pagination, check if a page exists
		if (!$pagination->valid_page($page) && $pagination->__get('total_pages') > 0) {
			$get['page'] = $pagination->__get('total_pages');
			Request::instance()->redirect($this->request->uri.'?'.http_build_query($get, '&'));
		}
		
		
		//collect the orm objects
		$objects = (isset($this->base_object)) ? $this->base_object->reset(false) : ORM::factory($this->orm_name);
		$objects
			->offset($offset)
			->limit(20);
		foreach ($filter as $field => $value) {
			$objects->and_where($field, 'like', '%' . $value . '%');
		}
		$objects = $objects->find_all();
{'fraction_non_alphanumeric': 0.21409037635108738, 'fraction_numerical': 0.002604505795025394, 'mean_word_length': 4.00651890482399, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 145, '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': '352120', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2478, 'n_words': 468}