freenetis-github/application/controllers/login_logs.php @ 53cf4ce8
8baed187 | Michal Kliment | <?php defined('SYSPATH') or die('No direct script access.');
|
|
/*
|
|||
* This file is part of open source system FreenetIS
|
|||
* and it is released under GPLv3 licence.
|
|||
*
|
|||
* More info about licence can be found:
|
|||
* http://www.gnu.org/licenses/gpl-3.0.html
|
|||
*
|
|||
* More info about project can be found:
|
|||
* http://www.freenetis.org/
|
|||
*
|
|||
*/
|
|||
/**
|
|||
* Controller displays login logs of user to system.
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @package Controller
|
|||
*/
|
|||
class Login_logs_Controller extends Controller
|
|||
{
|
|||
/**
|
|||
* Index redirects to show all
|
|||
*/
|
|||
public function index()
|
|||
{
|
|||
url::redirect('login_logs/show_all');
|
|||
}
|
|||
/**
|
|||
* Shows last time login of users
|
|||
*
|
|||
* @author Michal Kliment
|
|||
*/
|
|||
c1bdc1c4 | Michal Kliment | public function show_all($limit_results = 50, $order_by = 'last_time',
|
|
$order_by_direction = 'DESC', $page_word = null, $page = 1)
|
|||
8baed187 | Michal Kliment | {
|
|
// access
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_view('Login_logs_Controller', 'logs'))
|
|
8baed187 | Michal Kliment | Controller::error(ACCESS);
|
|
c1bdc1c4 | Michal Kliment | // filter
|
|
$filter_form = new Filter_form();
|
|||
$filter_form->add('name')
|
|||
->callback('json/user_name');
|
|||
$filter_form->add('id')
|
|||
->label('ID')
|
|||
->type('number');
|
|||
$filter_form->add('last_time')
|
|||
->label('Time of login')
|
|||
->type('date');
|
|||
8baed187 | Michal Kliment | // gets new selector
|
|
c1bdc1c4 | Michal Kliment | if (is_numeric($this->input->post('record_per_page')))
|
|
$limit_results = (int) $this->input->post('record_per_page');
|
|||
8baed187 | Michal Kliment | ||
$login_log_model = new Login_log_Model();
|
|||
c1bdc1c4 | Michal Kliment | $total_login_logs = $login_log_model->count_all_login_logs($filter_form->as_sql());
|
|
8baed187 | Michal Kliment | ||
if (($sql_offset = ($page - 1) * $limit_results) > $total_login_logs)
|
|||
$sql_offset = 0;
|
|||
$login_logs = $login_log_model->get_all_login_logs(
|
|||
c1bdc1c4 | Michal Kliment | $sql_offset, (int) $limit_results, $order_by,
|
|
$order_by_direction, $filter_form->as_sql()
|
|||
8baed187 | Michal Kliment | );
|
|
// create grid
|
|||
$grid = new Grid('login_logs/show_all', __('Login logs'), array
|
|||
(
|
|||
c1bdc1c4 | Michal Kliment | 'use_paginator' => true,
|
|
'use_selector' => true,
|
|||
'current' => $limit_results,
|
|||
'selector_increace' => 50,
|
|||
'selector_min' => 50,
|
|||
'selector_max_multiplier' => 10,
|
|||
'uri_segment' => 'page',
|
|||
'base_url' => Config::get('lang') . '/login_logs/show_all/'
|
|||
. $limit_results.'/'.$order_by.'/'.$order_by_direction,
|
|||
'total_items' => $total_login_logs,
|
|||
'items_per_page' => $limit_results,
|
|||
'style' => 'classic',
|
|||
'order_by' => $order_by,
|
|||
'order_by_direction' => $order_by_direction,
|
|||
'limit_results' => $limit_results,
|
|||
'filter' => $filter_form->html()
|
|||
8baed187 | Michal Kliment | ));
|
|
c1bdc1c4 | Michal Kliment | $grid->order_field('id');
|
|
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $grid->order_field('name');
|
|
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | $grid->order_field('last_time')
|
|
->label('Last time login');
|
|||
8baed187 | Michal Kliment | ||
$actions = $grid->grouped_action_field();
|
|||
$actions->add_action()
|
|||
->icon_action('member')
|
|||
->url('users/show')
|
|||
->label('Show user');
|
|||
$actions->add_action()
|
|||
->icon_action('login')
|
|||
->url('login_logs/show_by_user')
|
|||
->label('Show logins of user');
|
|||
$grid->datasource($login_logs);
|
|||
$view = new View('main');
|
|||
$view->title = __('Login logs');
|
|||
$view->breadcrumbs = __('Login logs');
|
|||
$view->content = $grid;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
/**
|
|||
* Show login logs of user
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $user_id
|
|||
* @param integer $limit_results
|
|||
* @param string $order_by
|
|||
* @param string $order_by_direction
|
|||
* @param integer $page_word
|
|||
* @param integer $page
|
|||
*/
|
|||
public function show_by_user(
|
|||
$user_id = null, $limit_results = 200, $order_by = 'time',
|
|||
$order_by_direction = 'desc', $page_word = null, $page = 1)
|
|||
{
|
|||
if (!isset($user_id))
|
|||
Controller::warning(PARAMETER);
|
|||
$user = new User_Model((int) $user_id);
|
|||
if (!$user->id)
|
|||
Controller::error(RECORD);
|
|||
// access
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_view('Login_logs_Controller', 'logs', $user->member_id))
|
|
8baed187 | Michal Kliment | {
|
|
Controller::error(ACCESS);
|
|||
}
|
|||
c1bdc1c4 | Michal Kliment | ||
// filter
|
|||
$filter_form = new Filter_form();
|
|||
$filter_form->add('time')
|
|||
->label('Time of login')
|
|||
->type('date');
|
|||
$filter_form->add('ip_address');
|
|||
8baed187 | Michal Kliment | ||
// gets new selector
|
|||
c1bdc1c4 | Michal Kliment | if (is_numeric($this->input->post('record_per_page')))
|
|
$limit_results = (int) $this->input->post('record_per_page');
|
|||
8baed187 | Michal Kliment | ||
$login_log_model = new Login_log_Model();
|
|||
c1bdc1c4 | Michal Kliment | $total_login_logs = $login_log_model->count_all_login_logs_by_user(
|
|
$user->id, $filter_form->as_sql()
|
|||
);
|
|||
8baed187 | Michal Kliment | ||
if (($sql_offset = ($page - 1) * $limit_results) > $total_login_logs)
|
|||
$sql_offset = 0;
|
|||
$login_logs = $login_log_model->get_all_login_logs_by_user(
|
|||
$user->id, $sql_offset, (int) $limit_results,
|
|||
c1bdc1c4 | Michal Kliment | $order_by, $order_by_direction, $filter_form->as_sql()
|
|
8baed187 | Michal Kliment | );
|
|
$headline = __('Login logs of user') . ' ' . $user->get_full_name();
|
|||
// create grid
|
|||
$grid = new Grid('login_logs/show_by_user', null, array
|
|||
(
|
|||
c1bdc1c4 | Michal Kliment | 'current' => $limit_results,
|
|
'selector_increace' => 200,
|
|||
'selector_min' => 200,
|
|||
'selector_max_multiplier' => 10,
|
|||
'uri_segment' => 'page',
|
|||
'base_url' => Config::get('lang') . '/login_logs/show_by_user/'
|
|||
. $user->id . '/' . $limit_results . '/'
|
|||
. $order_by . '/' . $order_by_direction,
|
|||
'total_items' => $total_login_logs,
|
|||
'items_per_page' => $limit_results,
|
|||
'style' => 'classic',
|
|||
'order_by' => $order_by,
|
|||
'order_by_direction' => $order_by_direction,
|
|||
'limit_results' => $limit_results,
|
|||
'variables' => $user->id . '/',
|
|||
'url_array_ofset' => 1,
|
|||
'filter' => $filter_form->html()
|
|||
8baed187 | Michal Kliment | ));
|
|
c1bdc1c4 | Michal Kliment | $grid->order_field('id')
|
|
->label('ID');
|
|||
8baed187 | Michal Kliment | ||
$grid->order_field('time');
|
|||
$grid->order_field('ip_address')
|
|||
c1bdc1c4 | Michal Kliment | ->label('IP address');
|
|
8baed187 | Michal Kliment | ||
$grid->datasource($login_logs);
|
|||
$breadcrumbs = breadcrumbs::add()
|
|||
->link('members/show_all', 'Members',
|
|||
$this->acl_check_view('Members_Controller', 'members'))
|
|||
->link('members/show/' . $user->member->id,
|
|||
'ID ' . $user->member->id . ' - ' . $user->member->name,
|
|||
$this->acl_check_view('Members_Controller', 'members', $user->member->id))
|
|||
->link('users/show_by_member/' . $user->member_id, 'Users',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Users_Controller', 'users', $user->member_id))
|
|
8baed187 | Michal Kliment | ->link('users/show/' . $user->id,
|
|
$user->name . ' ' . $user->surname . ' (' . $user->login . ')',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Users_Controller', 'users', $user->member_id))
|
|
8baed187 | Michal Kliment | ->text('Login logs');
|
|
$view = new View('main');
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->title = $headline;
|
|||
$view->content = new View('show_all');
|
|||
$view->content->headline = $headline;
|
|||
$view->content->table = $grid;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
}
|