freenetis-github/application/controllers/aro_groups.php @ 897b8a43
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 performs actions with ARO groups of users
|
|||
*/
|
|||
class Aro_groups_Controller extends Controller
|
|||
{
|
|||
/**
|
|||
* Index function, only redirects to list of ARO groups
|
|||
*/
|
|||
public function index()
|
|||
{
|
|||
url::redirect('aro_groups/show_all');
|
|||
}
|
|||
/**
|
|||
* Shows access groups
|
|||
*/
|
|||
public function show_all()
|
|||
{
|
|||
// check access
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | {
|
|
Controller::Error(ACCESS);
|
|||
}
|
|||
$rows = array();
|
|||
$aro_group_model = new Aro_group_Model();
|
|||
$groups = $aro_group_model->get_traverz_tree();
|
|||
$model_groups_aro_map = new Groups_Aro_Map_Model();
|
|||
// vykresleni skupin
|
|||
for ($i = 0; $i < $groups->count(); $i++)
|
|||
{
|
|||
$group = $groups->current();
|
|||
$ret = '';
|
|||
$rows[0] = '<tr><th colspan="5" style="width:300px">'
|
|||
. __('Edit groups') . '</th></tr>';
|
|||
//vypocet posunuti podskupiny
|
|||
$parents_count = Aro_group_Model::count_parent($group->id);
|
|||
for ($j = 0; $j < $parents_count - 1; $j++)
|
|||
{
|
|||
$ret .= ' ';
|
|||
}
|
|||
$count = $model_groups_aro_map->count_rows_by_group_id($group->id);
|
|||
c2e44ab0 | Michal Kliment | if ($group->id == Aro_group_Model::ALL)
|
|
8baed187 | Michal Kliment | {
|
|
$rows[$i + 1] = '<tr><td style="width:400px">'
|
|||
. $ret . __('' . $group->name)
|
|||
. '</td><td style="width:30px; text-align: center" >'
|
|||
. $count . '</td><td>'
|
|||
. __('Show')
|
|||
c1bdc1c4 | Michal Kliment | .'</td>';
|
|
if ($this->acl_check_edit('Aro_groups_Controller', 'aro_group'))
|
|||
{
|
|||
$rows[$i + 1] .= '<td>' . __('Edit') . '</td>';
|
|||
}
|
|||
if ($this->acl_check_delete('Aro_groups_Controller', 'aro_group'))
|
|||
{
|
|||
$rows[$i + 1] .= '<td>' . __('Delete') . '</td>';
|
|||
}
|
|||
$rows[$i + 1] .= '</tr>';
|
|||
8baed187 | Michal Kliment | }
|
|
else
|
|||
{
|
|||
$rows[$i + 1] = '<tr><td style="width:400px">'
|
|||
. $ret . $group->name
|
|||
. '</td><td style="width:30px; text-align: center" >'
|
|||
. $count . '</td><td>'
|
|||
. html::anchor('aro_groups/show/'.$group->id, __('Show'))
|
|||
c1bdc1c4 | Michal Kliment | .'</td>';
|
|
if ($this->acl_check_edit('Aro_groups_Controller', 'aro_group'))
|
|||
{
|
|||
$rows[$i + 1] .= '<td>' . html::anchor(url_lang::base()
|
|||
8baed187 | Michal Kliment | . 'aro_groups/edit/' . $group->id, __('Edit'))
|
|
c1bdc1c4 | Michal Kliment | . '</td>';
|
|
}
|
|||
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if ($this->acl_check_delete('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | $rows[$i + 1] .= '<td>';
|
|
if (!$aro_group_model->count_childrens($group->id) &&
|
|||
$aro_group_model->is_deletable($group->id))
|
|||
{
|
|||
$rows[$i + 1] .= html::anchor(url_lang::base()
|
|||
. 'aro_groups/delete/' . $group->id, __('Delete'),
|
|||
array('class' => 'delete_link'));
|
|||
}
|
|||
else
|
|||
$rows[$i + 1] .= __('Delete');
|
|||
$rows[$i + 1] .= '</td>';
|
|||
8baed187 | Michal Kliment | }
|
|
c1bdc1c4 | Michal Kliment | $rows[$i + 1] .= '</tr>';
|
|
8baed187 | Michal Kliment | }
|
|
$groups->next();
|
|||
}
|
|||
$headline = __('Access control groups of users');
|
|||
$links[] = html::anchor('aro_groups/show_all', __('Groups of users'));
|
|||
$links[] = html::anchor('access_rights/show_acl', __('Access control list items'));
|
|||
$breadcrumbs = breadcrumbs::add()
|
|||
->text('Access control groups of users');
|
|||
c1bdc1c4 | Michal Kliment | if ($this->acl_check_view('Acl_Controller', 'acl'))
|
|
{
|
|||
$submenu = array();
|
|||
$submenu['acl/show_all'] = __('Access control rules');
|
|||
$submenu['aro_groups/show_all'] = __('Access control groups of users');
|
|||
}
|
|||
else
|
|||
{
|
|||
$submenu = NULL;
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
//vykresleni
|
|||
$view = new View('main');
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->title = $headline;
|
|||
$view->content = new View('access_rights/aro_groups_show_all');
|
|||
c1bdc1c4 | Michal Kliment | $this->sections = $submenu;
|
|
$view->content->current = 'aro_groups/show_all';
|
|||
8baed187 | Michal Kliment | $view->content->links = implode(' | ', $links);
|
|
$view->content->rows = $rows;
|
|||
$view->content->headline = $headline;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
/**
|
|||
* Shows access control group
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $group_id
|
|||
*/
|
|||
public function show ($group_id = NULL)
|
|||
{
|
|||
// access check
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | Controller::Error(ACCESS);
|
|
// bad parameter
|
|||
if (!$group_id || !is_numeric($group_id))
|
|||
Controller::warning(PARAMETER);
|
|||
$aro_group = new Aro_group_Model($group_id);
|
|||
// record doesn't exist
|
|||
if (!$aro_group->id)
|
|||
Controller::error(RECORD);
|
|||
/** AROs **/
|
|||
$aros = $aro_group->get_aros();
|
|||
// grid
|
|||
$aro_grid = new Grid(url_lang::base().'aro', null, array
|
|||
(
|
|||
'use_paginator' => false,
|
|||
'use_selector' => false,
|
|||
'total_items' => count($aros)
|
|||
));
|
|||
$aro_grid->field('id')
|
|||
->label(__('ID'));
|
|||
$aro_grid->link_field('id')
|
|||
->link('users/show', 'user_name')
|
|||
->label(__('User'));
|
|||
$aro_grid->datasource($aros);
|
|||
/** ACLs **/
|
|||
$acls = $aro_group->get_acls();
|
|||
// grid
|
|||
$acl_grid = new Grid(url_lang::base().'acl', null, array
|
|||
(
|
|||
'use_paginator' => false,
|
|||
'use_selector' => false,
|
|||
'total_items' => count($acls)
|
|||
));
|
|||
$acl_grid->field('id')
|
|||
->label(__('ID'));
|
|||
$acl_grid->callback_field('note')
|
|||
->label(__('Description'))
|
|||
->callback('callback::limited_text');
|
|||
$actions = $acl_grid->grouped_action_field();
|
|||
c1bdc1c4 | Michal Kliment | if ($this->acl_check_view('Acl_Controller', 'acl'))
|
|
{
|
|||
$actions->add_action('id')
|
|||
->icon_action('show')
|
|||
->url('acl/show');
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if ($this->acl_check_edit('Acl_Controller', 'acl'))
|
|
{
|
|||
$actions->add_action('id')
|
|||
->icon_action('edit')
|
|||
->url('acl/edit');
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
c1bdc1c4 | Michal Kliment | if ($this->acl_check_delete('Acl_Controller', 'acl'))
|
|
{
|
|||
$actions->add_action('id')
|
|||
->icon_action('delete')
|
|||
->url('acl/delete')
|
|||
->class('delete_link');
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
$acl_grid->datasource($acls);
|
|||
$headline = __('Show access control group of users');
|
|||
$breadcrumbs = breadcrumbs::add()
|
|||
->link('aro_groups/show_all', 'Access control groups of users',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | ->disable_translation()
|
|
->text($aro_group->name.' ('.$aro_group->id.')');
|
|||
$view = new View('main');
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->title = $headline;
|
|||
$view->content = new View('access_rights/aro_groups_show');
|
|||
$view->content->aro_group = $aro_group;
|
|||
$view->content->parent = $aro_group->get_parent();
|
|||
$view->content->aro_grid = $aro_grid;
|
|||
$view->content->acl_grid = $acl_grid;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
/**
|
|||
* Adds new access control group
|
|||
*
|
|||
* @author Michal Kliment
|
|||
*/
|
|||
public function add()
|
|||
{
|
|||
// check access
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_new('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | Controller::Error(ACCESS);
|
|
$aro_group_model = new Aro_group_Model();
|
|||
$aro_groups = $aro_group_model->get_traverz_tree();
|
|||
$arr_aro_groups = array();
|
|||
foreach ($aro_groups as $aro_group)
|
|||
{
|
|||
$ret = '';
|
|||
$parents_count = Aro_group_Model::count_parent($aro_group->id);
|
|||
for($j = 0; $j < $parents_count - 1; $j++ )
|
|||
$ret .= ' ';
|
|||
$arr_aro_groups[$aro_group->id] = $ret.__(''.$aro_group->name);
|
|||
}
|
|||
// form
|
|||
$form = new Forge(url::base(TRUE) . url::current(TRUE));
|
|||
$form->input('name')
|
|||
->rules('required')
|
|||
->style('width:600px');
|
|||
$form->dropdown('parent_id')
|
|||
->label('Parent')
|
|||
->options($arr_aro_groups)
|
|||
->rules('required')
|
|||
->style('width:600px');
|
|||
$form->submit('Add');
|
|||
// form is validate
|
|||
if ($form->validate())
|
|||
{
|
|||
$form_data = $form->as_array();
|
|||
$aro_group = new Aro_group_Model($form_data['parent_id']);
|
|||
c1bdc1c4 | Michal Kliment | if ($aro_group->id)
|
|
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | try
|
|
8baed187 | Michal Kliment | {
|
|
c1bdc1c4 | Michal Kliment | $aro_group->transaction_start();
|
|
8baed187 | Michal Kliment | $rgt = $aro_group->rgt;
|
|
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | $aro_group->increase($rgt);
|
|
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | $aro_group->clear();
|
|
$aro_group->parent_id = $form_data['parent_id'];
|
|||
$aro_group->lft = $rgt;
|
|||
$aro_group->rgt = $rgt+1;
|
|||
$aro_group->name = $form_data['name'];
|
|||
$aro_group->value = url::title($form_data['name'], '_');
|
|||
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | $aro_group->save_throwable();
|
|
$aro_group->transaction_commit();
|
|||
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | status::success('Group has been successfully added.');
|
|
}
|
|||
c1bdc1c4 | Michal Kliment | catch (Exception $e)
|
|
{
|
|||
$aro_group->transaction_rollback();
|
|||
Log::add_exception($e);
|
|||
status::error('Error - cannot add new group.', $e);
|
|||
}
|
|||
8baed187 | Michal Kliment | }
|
|
c1bdc1c4 | Michal Kliment | ||
8baed187 | Michal Kliment | url::redirect('aro_groups/show_all');
|
|
}
|
|||
$headline = __('Add new group');
|
|||
$breadcrumbs = breadcrumbs::add()
|
|||
->link('aro_groups/show_all', 'Access control groups of users',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | ->text($headline);
|
|
$view = new View('main');
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->title = $headline;
|
|||
$view->content = new View('form');
|
|||
$view->content->headline = $headline;
|
|||
$view->content->form = $form;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
/**
|
|||
* Edits ARO group
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $group_id
|
|||
*/
|
|||
public function edit ($group_id = NULL)
|
|||
{
|
|||
// access check
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_edit('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | Controller::Error(ACCESS);
|
|
// bad parameter
|
|||
if (!$group_id || !is_numeric($group_id))
|
|||
Controller::warning(PARAMETER);
|
|||
$aro_group = new Aro_group_Model($group_id);
|
|||
// record doesn't exist
|
|||
if (!$aro_group->id)
|
|||
Controller::error(RECORD);
|
|||
$form = new Forge(url::base(TRUE).url::current(TRUE));
|
|||
$form->input('name')
|
|||
->rules('required')
|
|||
->value($aro_group->name)
|
|||
->style('width:600px');
|
|||
$user_model = new User_Model();
|
|||
$users = $user_model->select_list_grouped(FALSE);
|
|||
$sel_aros = array();
|
|||
foreach ($aro_group->get_aros() as $aro)
|
|||
$sel_aros[] = $aro->id;
|
|||
$form->dropdown('aro[]')
|
|||
->label('User')
|
|||
->options($users)
|
|||
->selected($sel_aros)
|
|||
->multiple('multiple')
|
|||
->size(20);
|
|||
$form->submit('submit')
|
|||
->value(__('Update'));
|
|||
// form is validate
|
|||
if ($form->validate())
|
|||
{
|
|||
$form_data = $form->as_array();
|
|||
$aro = (isset($_POST["aro"])) ? $_POST["aro"] : array();
|
|||
try
|
|||
{
|
|||
$aro_group->transaction_start();
|
|||
// update name of group
|
|||
$aro_group->name = $form_data['name'];
|
|||
$aro_group->save_throwable();
|
|||
// cleans group - remove all old AROs
|
|||
$aro_group->clean_group();
|
|||
// inserts new AROs
|
|||
$aro_group->insert_aro($aro);
|
|||
$aro_group->transaction_commit();
|
|||
status::success('Access control group of users has been successfully updated.');
|
|||
}
|
|||
catch (Exception $e)
|
|||
{
|
|||
$aro_group->transaction_rollback();
|
|||
Log::add_exception($e);
|
|||
c1bdc1c4 | Michal Kliment | status::error('Error - cannot update access control group.', $e);
|
|
8baed187 | Michal Kliment | }
|
|
url::redirect (url_lang::base().'aro_groups/show/'.$aro_group->id);
|
|||
}
|
|||
$headline = __('Edit access control group of users');
|
|||
$breadcrumbs = breadcrumbs::add()
|
|||
->link('aro_groups/show_all', 'Access control groups of users',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | ->disable_translation()
|
|
->link('aro_groups/show/'.$aro_group->id, $aro_group->name.' ('.$aro_group->id.')',
|
|||
c1bdc1c4 | Michal Kliment | $this->acl_check_view('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | ->enable_translation()
|
|
->text('Edit');
|
|||
$view = new View('main');
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->title = $headline;
|
|||
$view->content = new View('form');
|
|||
$view->content->headline = $headline;
|
|||
$view->content->form = $form;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
18ac9009 | Ondřej Fibich | ||
/**
|
|||
* Edits ARO groups of user
|
|||
*
|
|||
* @author David Raska
|
|||
* @param integer $user_id
|
|||
*/
|
|||
public function edit_user ($user_id = NULL)
|
|||
{
|
|||
// bad parameter
|
|||
if (!$user_id || !is_numeric($user_id))
|
|||
Controller::warning(PARAMETER);
|
|||
// record doesn't exist
|
|||
if (!$user_id)
|
|||
Controller::error(RECORD);
|
|||
$user = new User_Model($user_id);
|
|||
// access check
|
|||
if (!$this->acl_check_edit('Aro_groups_Controller', 'aro_group'))
|
|||
Controller::Error(ACCESS);
|
|||
$form = new Forge(url::base(TRUE).url::current(TRUE));
|
|||
$aro_groups_model = new Aro_group_Model();
|
|||
$aro_groups = $aro_groups_model->select_list();
|
|||
$users_aro_groups = $user->get_aro_groups_of_user($user_id);
|
|||
$sel_groups = array();
|
|||
foreach ($users_aro_groups as $aro)
|
|||
$sel_groups[] = $aro->id;
|
|||
$form->dropdown('groups[]')
|
|||
->label('Aro groups')
|
|||
->options($aro_groups)
|
|||
->selected($sel_groups)
|
|||
->multiple('multiple')
|
|||
->size(20);
|
|||
$form->submit('submit')
|
|||
->value(__('Update'));
|
|||
// form is validate
|
|||
if ($form->validate())
|
|||
{
|
|||
$form_data = $form->as_array();
|
|||
$groups = (isset($_POST["groups"])) ? $_POST["groups"] : array();
|
|||
try
|
|||
{
|
|||
$aro_groups_model->transaction_start();
|
|||
// cleans group - remove all old AROs
|
|||
$aro_groups_model->clean_aro($user_id);
|
|||
// inserts new AROs
|
|||
$aro_groups_model->insert_groups($groups, $user_id);
|
|||
$aro_groups_model->transaction_commit();
|
|||
status::success('Access control groups of user has been successfully updated.');
|
|||
}
|
|||
catch (Exception $e)
|
|||
{
|
|||
$aro_groups_model->transaction_rollback();
|
|||
Log::add_exception($e);
|
|||
status::error('Error - cannot update access control groups.', $e);
|
|||
}
|
|||
url::redirect (url_lang::base().'users/show/'.$user_id);
|
|||
}
|
|||
$headline = __('Edit access control groups of user');
|
|||
// breadcrumbs navigation
|
|||
$breadcrumbs = breadcrumbs::add()
|
|||
->link('members/show_all', 'Members',
|
|||
$this->acl_check_view('Members_Controller','members'))
|
|||
->disable_translation()
|
|||
->link('members/show/' . $user->member->id,
|
|||
"ID ".$user->member->id." - ".$user->member->name,
|
|||
$this->acl_check_view(
|
|||
'Members_Controller','members', $user->member->id
|
|||
)
|
|||
)->enable_translation()
|
|||
->link('users/show_by_member/' . $user->member_id, 'Users',
|
|||
$this->acl_check_view(
|
|||
'Users_Controller', 'users', $user->member_id
|
|||
)
|
|||
)
|
|||
->link('users/show/' . $user_id, "$user->name $user->surname ($user->login)",
|
|||
$this->acl_check_view(
|
|||
'Users_Controller', 'users', $user->member_id
|
|||
)
|
|||
)
|
|||
->text($headline);
|
|||
$view = new View('main');
|
|||
$view->breadcrumbs = $breadcrumbs->html();
|
|||
$view->title = $headline;
|
|||
$view->content = new View('form');
|
|||
$view->content->headline = $headline;
|
|||
$view->content->form = $form;
|
|||
$view->render(TRUE);
|
|||
}
|
|||
8baed187 | Michal Kliment | ||
/**
|
|||
* Deletes group
|
|||
*
|
|||
* @author Michal Kliment
|
|||
* @param integer $group_id
|
|||
*/
|
|||
public function delete ($group_id = NULL)
|
|||
{
|
|||
// access check
|
|||
c1bdc1c4 | Michal Kliment | if (!$this->acl_check_delete('Aro_groups_Controller', 'aro_group'))
|
|
8baed187 | Michal Kliment | Controller::Error(ACCESS);
|
|
// bad parameter
|
|||
if (!$group_id || !is_numeric($group_id))
|
|||
Controller::warning (PARAMETER);
|
|||
$group = new Aro_group_Model($group_id);
|
|||
// record doesn't exist
|
|||
if (!$group->id)
|
|||
Controller::error(RECORD);
|
|||
c2e44ab0 | Michal Kliment | // cannot delete group with some childrens
|
|
if (!$group->is_deletable())
|
|||
{
|
|||
status::warning('Cannot delete group - this group is protected against deletion');
|
|||
url::redirect('aro_groups/show_all');
|
|||
}
|
|||
8baed187 | Michal Kliment | // cannot delete group with some childrens
|
|
if ($group->count_childrens())
|
|||
{
|
|||
status::warning('Cannot delete group - it has at least one children group');
|
|||
c2e44ab0 | Michal Kliment | url::redirect('aro_groups/show_all');
|
|
8baed187 | Michal Kliment | }
|
|
$group->transaction_start();
|
|||
try
|
|||
{
|
|||
$lft = $group->lft;
|
|||
$group->delete_throwable();
|
|||
$group->decrease($lft);
|
|||
$group->transaction_commit();
|
|||
status::success('Group has been successfully deleted.');
|
|||
}
|
|||
catch (Exception $e)
|
|||
{
|
|||
$group->transaction_rollback();
|
|||
Log::add_exception($e);
|
|||
c1bdc1c4 | Michal Kliment | status::error('Error - cannot delete group.', $e);
|
|
8baed187 | Michal Kliment | }
|
|
url::redirect('aro_groups/show_all');
|
|||
}
|
|||
}
|