Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8baed187

Přidáno uživatelem Michal Kliment před asi 9 roky(ů)

Release 1.0.0

Zobrazit rozdíly:

.htaccess-sample
RewriteEngine On
RewriteBase /
# Protect application and system files from being viewed.
RewriteCond $1 ^(application|system)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ access_denied/$1 [PT,L]
# URL containing these strings will not be rewrited.
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media|redirection)
RewriteRule ^(.*)$ - [PT,L]
# Force EVERY URL to contain a language in its first segment.
# Redirect URLs without a language to the invalid xx language.
RewriteCond $2 !^([a-z]{2}(/|$)) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(index\.php/?)?(.*)$ en/$2 [R=301,L]
# Silently prepend index.php to EVERY URL.
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
AUTHORS
Tomáš Dulík <dulik@unart.cz>
Ondřej Fibich <ondrej.fibich@gmail.com>
Michal Kliment <kliment@freenetis.org>
David Raška <jeffraska@gmail.com>
Jiří Sviták <j.svitak@unart.cz>
Roman Ševčík <sevcik.roman@mail.unart.cz>
COPYING
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
application/controllers/accounts.php
<?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/
*
*/
/**
* Manages all double-entry accounts in the system including accounting system.
*
* @author Jiri Svitak
* @package Controller
*/
class Accounts_Controller extends Controller
{
/**
* Index redirect to show all
*/
public function index()
{
url::redirect('accounts/show_all/1');
}
/**
* It shows all double-entry accounts.
* They are shown by selected group in filter.
*
* @author Jiri Svitak
* @param $limit_results
* @param $order_by
* @param $order_by_direction
*/
public function show_all(
$group = 1, $limit_results = 500, $order_by = 'id',
$order_by_direction = 'asc', $page_word = null, $page = 1)
{
// access check
if (!$this->acl_check_view('Accounts_Controller', 'accounts'))
{
Controller::error(ACCESS);
}
// account groups
$arr_groups[Account_Model::ACCOUNTING_SYSTEM] = __('Accounting system');
$arr_groups[Account_Model::CREDIT] = __('Credit subaccounts');
$arr_groups[Account_Model::PROJECT] = __('Project subaccounts');
$arr_groups[Account_Model::OTHER] = __('Other');
// account groups with help
$arr_groups_help[Account_Model::ACCOUNTING_SYSTEM] = help::hint('accounting_system');
$arr_groups_help[Account_Model::CREDIT] = help::hint('credit_subaccounts');
$arr_groups_help[Account_Model::PROJECT] = help::hint('project_subaccounts');
$arr_groups_help[Account_Model::OTHER] = help::hint('other_subaccounts');
// filtering
$filter = new Table_Form(url_lang::base() . "accounts/show_all/$group", "get", array
(
new Table_Form_Item('text', 'name', 'Account name'),
"tr",
new Table_Form_Item('text', 'datetime_from', 'Balance from date'),
"tr",
new Table_Form_Item('text', 'datetime_to', 'Balance to date'),
"tr",
"td", new Table_Form_Item('submit', 'submit', 'Filter'),
));
$filter_values = $filter->values();
// gets grid settings
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
// order by check
$allowed_order_type = array('id', 'aname', 'comment', 'mname', 'balance');
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
// order by direction check
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
// gets records
if ($group == Account_Model::ACCOUNTING_SYSTEM)
{
$account_attribute_model = new Account_attribute_Model();
$total_accounts = $account_attribute_model->get_accounting_system_count($filter_values);
if (($sql_offset = ($page - 1) * $limit_results) > $total_accounts)
$sql_offset = 0;
$accounts = $account_attribute_model->get_accounting_system(
$sql_offset, (int) $limit_results, $order_by,
$order_by_direction, $filter_values
);
}
else
{
$account_model = new Account_Model();
$total_accounts = $account_model->get_accounts_count($filter_values, $group);
if (($sql_offset = ($page - 1) * $limit_results) > $total_accounts)
$sql_offset = 0;
$accounts = $account_model->get_accounts(
$sql_offset, (int) $limit_results, $order_by,
$order_by_direction, $filter_values, $group
);
}
// creates parameters of filter in url
$arr_gets = array();
foreach ($this->input->get() as $key => $value)
{
$arr_gets[] = $key . '=' . $value;
}
$query_string = '?' . implode('&', $arr_gets);
// set correct headline for chosen group
$headline = $arr_groups[$group];
// grid
$grid = new Grid('accounts', null, array
(
'current' => $limit_results,
'selector_increace' => 500,
'selector_min' => 500,
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang') . '/accounts/show_all/' . $group . '/'
. $limit_results . '/' . $order_by . '/' . $order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_accounts,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'query_string' => $query_string,
'filter' => $filter->view,
'variables' => $group . '/',
'url_array_ofset' => 1
));
foreach ($arr_groups as $key => $arr_group)
{
$grid->add_new_button(
'accounts/show_all/' . $key,
$arr_group, array(), $arr_groups_help[$key]
);
}
if ($group == Account_Model::ACCOUNTING_SYSTEM)
{
// button for recalculating balances of all accounts
if ($this->acl_check_edit('Accounts_Controller', 'accounts'))
{
$grid->add_new_button(
'accounts/recalculate_account_balances',
__('Recalculate account balances'),
array(), help::hint('recalculate_account_balances')
);
}
$grid->order_field('id')
->label(__('Account'));
$grid->order_field('name')
->label(__('Account name'));
$grid->order_callback_field('balance')
->callback('callback::balance_field');
}
else
{
// adding project account
if ($group == Account_Model::PROJECT &&
$this->acl_check_new('Accounts_Controller', 'accounts'))
{
$grid->add_new_button(
'accounts/add_project',
__('Add new project account')
);
}
$grid->order_field('id');
$grid->order_field('name')
->label(__('Account name'));
$grid->order_field('account_attribute_id')
->label(__('Type'));
$grid->order_callback_field('balance')
->callback('callback::balance_field');
$grid->order_callback_field('member_name')
->callback('callback::member_field');
$actions = $grid->grouped_action_field();
if ($this->acl_check_view('Accounts_Controller', 'transfers'))
{
$actions->add_action('id')
->icon_action('transfer')
->url('transfers/show_by_account')
->label('Show transfers');
}
if ($this->acl_check_edit('Accounts_Controller', 'accounts'))
{
$actions->add_action('id')
->icon_action('edit')
->url('accounts/edit')
->label('Edit account');
}
}
// load data
$grid->datasource($accounts);
// bread crumbs
$breadcrumbs = breadcrumbs::add(false)
->text($headline)
->html();
// view
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $breadcrumbs;
$view->content = new View('show_all');
$view->content->headline = $headline . '&nbsp;' . $arr_groups_help[$group];
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Adds new project account.
*
* @author Jiri Svitak
* @param integer $member_id
*/
public function add_project()
{
// access rights
if (!$this->acl_check_new('Accounts_Controller', 'accounts'))
{
Controller::error(ACCESS);
}
// members list
$arr_members = ORM::factory('member')
->select_list('id', "CONCAT(id, ' - ', COALESCE(name,''))", 'name');
// form
$form = new Forge('accounts/add_project');
$form->group('Basic information');
$form->dropdown('member')
->label(__('Owner') . ':')
->rules('required')
->options($arr_members)
->style('width:200px');
$form->input('name')
->label(__('Account name') . ':')
->rules('required|length[3,50]');
$form->textarea('comment')
->rules('length[0,250]');
$form->submit('Add');
// posted form
if ($form->validate())
{
$form_data = $form->as_array();
$account = new Account_Model;
$account->member_id = $form_data['member'];
$account->account_attribute_id = Account_attribute_Model::PROJECT;
$account->name = $form_data['name'];
$account->comment = $form_data['comment'];
unset($form_data);
if ($account->save())
{
status::success('Account has been successfully added.');
}
else
{
status::error('Error - cant add new account.');
}
url::redirect('accounts/show_all?name=&group=2&submit=Filter');
}
else
{
// headline
$headline = __('Add new project account');
// bread crumbs
$breadcrumbs = breadcrumbs::add()
->link('accounts/show_all/3', 'Project subaccounts',
$this->acl_check_view('Accounts_Controller', 'accounts'))
->disable_translation()
->text($headline)
->html();
// view
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $breadcrumbs;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->render(TRUE);
}
} // end of add_credit_account function
/**
* Function edits double-entry account.
*
* @param integer $acc_id
*/
public function edit($acc_id = NULL)
{
// access rights
if (!$this->acl_check_edit('Accounts_Controller', 'accounts'))
Controller::error(ACCESS);
if (!isset($acc_id) || !is_numeric($acc_id))
Controller::warning(PARAMETER);
$model_account = new Account_Model($acc_id);
if (!$model_account->id)
Controller::error(RECORD);
$form = new Forge('accounts/edit/' . $acc_id);
$form->group('Basic information');
$form->input('name')
->rules('required|length[3,50]')
->value($model_account->name)
->style('width:600px');
$form->textarea('comment')
->rules('length[0,250]')
->value($model_account->comment)
->style('width:600px');
$form->submit('Edit');
// form posted
if ($form->validate())
{
$form_data = $form->as_array();
$model_account->name = $form_data['name'];
$model_account->comment = $form_data['comment'];
unset($form_data);
if ($model_account->save())
{
status::success('Account has been successfully updated.');
}
else
{
status::error('Error - cant update account.');
}
url::redirect("accounts/show_all/1");
}
else
{
// bread crumbs
$breadcrumbs = breadcrumbs::add()
->link('accounts/show_all', 'Project subaccounts',
$this->acl_check_view('Accounts_Controller', 'accounts'))
->disable_translation()
->text($model_account->name . ' (' . $model_account->id . ')')
->html();
// headline
$headline = __('Edit account');
// view
$view = new View('main');
$view->title = $headline;
$view->breadcrumbs = $breadcrumbs;
$view->content = new View('form');
$view->content->headline = $headline;
$view->content->form = $form->html();
$view->render(TRUE);
}
} // end of edit function
/**
* Goes through all double-entry accounts and calculates their balance from their transfers.
* All transfers are primary information about cash flow. Calculating balance of account
* is creating redundant information, but it speeds up all money calculating operations in system.
* This method should be used only in special cases, like changing version of Freenetis
* to version containing this method, or when some data are corrupted.
* The user is familiar with result, when no change to balance is made, then everything is ok.
* In other case user is informed about count of accounts, which transfers are not corresponding
* to its balance
*
* @author Jiri Svitak
*/
public function recalculate_account_balances()
{
if (!$this->acl_check_edit('Accounts_Controller', 'accounts'))
{
Controller::error(ACCESS);
}
// get all accounts with their own and calculated balances
$account_model = new Account_Model();
// recalculates balances and returns array of ids of incorrect accounts
$incorrect_accounts = $account_model->recalculate_account_balances();
// message
status::success(
'All accounts now have correct balances, %d accounts had ' .
'incorrect balances, list of IDs of corrected accounts: %s',
TRUE, array
(
0 => count($incorrect_accounts),
1 => implode(", ", $incorrect_accounts)
)
);
// redirection
url::redirect('accounts/show_all');
}
}
application/controllers/acl.php
<?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 access control rules
*
* @package Controller
* @author Michal Kliment
*/
class Acl_Controller extends Controller
{
/**
* Index function, only redirect to list of all access control rules
*
* @author Michal Kliment
*/
public function index()
{
url::redirect('acl/show_all');
}
/**
* Shows all access control rules
*
* @author Michal Kliment
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param string $page_word
* @param integer $page
*/
public function show_all (
$limit_results = 100, $order_by = 'id',
$order_by_direction = 'asc',
$page_word = 'page', $page = 1)
{
// check access
if (!$this->acl_check_view('Settings_Controller', 'access_rights'))
Controller::Error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
// parameters control
$allowed_order_type = array
(
'id', 'desription', 'aco_count', 'aro_groups_count','axo_count'
);
// order by check
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
// order by direction check
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
$acl_model = new Acl_Model();
$total_rules = $acl_model->count_all_rules();
// limit check
if (($sql_offset = ($page - 1) * $limit_results) > $total_rules)
$sql_offset = 0;
$rules = $acl_model->get_all_rules(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction
);
$headline = __('List of all rules for access control');
// path to form
$path = Config::get('lang') . '/acl/show_all/' . $limit_results . '/'
. $order_by . '/' . $order_by_direction.'/'.$page_word.'/'
. $page;
// it creates grid to view all members
$grid = new Grid('acl', null, array
(
'current' => $limit_results,
'selector_increace' => 50,
'selector_min' => 100,
'selector_max_multiplier' => 20,
'base_url' => $path,
'uri_segment' => 'page',
'total_items' => $total_rules,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
//'filter' => $filter_form
));
$grid->add_new_button('acl/add', __('Add new rule'));
$grid->order_field('id')
->label(__('ID'));
$grid->order_callback_field('description')
->callback('callback::limited_text');
$grid->order_callback_field('aco_count')
->label(__('ACO count').' '.help::hint('aco_count'))
->callback('callback::aco_count_field')
->class('center');
$grid->order_callback_field('aro_groups_count')
->label(__('ARO groups count').' '.help::hint('aro_groups_count'))
->callback('callback::aro_groups_count_field')
->class('center');
$grid->order_callback_field('axo_count')
->label(__('AXO count').' '.help::hint('axo_count'))
->callback('callback::axo_count_field')
->class('center');
$actions = $grid->grouped_action_field();
$actions->add_action('id')
->icon_action('show')
->url('acl/show');
$actions->add_action('id')
->icon_action('edit')
->url('acl/edit');
$actions->add_action('id')
->icon_action('delete')
->url('acl/delete')
->class('delete_link');
$grid->datasource($rules);
$submenu = array();
$submenu[] = __('Access control rules');
$submenu[] = html::anchor('aro_groups/show_all', __('Access control groups of users'));
$view = new View('main');
$view->breadcrumbs = __('Access control rules');
$view->title = $headline;
$view->content = new View('show_all');
$view->content->submenu = implode(' | ',$submenu);
$view->content->headline = $headline;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Shows access control rule
*
* @author Michal Kliment
* @param integer $acl_id
*/
public function show ($acl_id = NULL)
{
// check access
if (!$this->acl_check_view('Settings_Controller', 'access_rights'))
Controller::Error(ACCESS);
// bad parameter
if (!$acl_id || !is_numeric($acl_id))
Controller::warning (PARAMETER);
$acl = new Acl_Model($acl_id);
// record doesn't exist
if (!$acl->id)
Controller::error(RECORD);
/** ACO **/
$acos = $acl->get_acos();
// grid
$aco_grid = new Grid(url_lang::base().'aco', null, array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($acos)
));
$aco_grid->callback_field('value')
->callback('callback::aco_value_field');
$aco_grid->datasource($acos);
/** ARO groups **/
$aro_groups = $acl->get_aro_groups();
// grid
$aro_groups_grid = new Grid(url_lang::base().'aro_groups', null, array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($aro_groups)
));
$aro_groups_grid->field('id')
->label(__('ID'));
$aro_groups_grid->field('name');
$aro_groups_grid->datasource($aro_groups);
/** AXO **/
$axos = $acl->get_axos();
// grid
$axo_grid = new Grid(url_lang::base().'axo', null, array
(
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($axos)
));
$axo_grid->field('id')
->label(__('ID'));
$axo_grid->field('section_value')
->label('Section');
$axo_grid->field('value');
$axo_grid->field('name');
$axo_grid->datasource($axos);
$headline = __('Show access control rule');
$breadcrumbs = breadcrumbs::add()
->link('acl/show_all', 'Access control rules',
$this->acl_check_view('Settings_Controller', 'access_rights'))
->text('ID '.$acl->id);
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('access_rights/acl_show');
$view->content->acl = $acl;
$view->content->aco_grid = $aco_grid;
$view->content->aro_groups_grid = $aro_groups_grid;
$view->content->axo_grid = $axo_grid;
$view->render(TRUE);
}
/**
* Adds new access control rule
*
* @author Michal Kliment
*/
public function add ()
{
// check access
if (!$this->acl_check_edit('Settings_Controller', 'access_rights'))
Controller::Error(ACCESS);
$form = new Forge(url::base(TRUE).url::current(TRUE));
$form->textarea('description')
->rules('required')
->style('width:600px');
$form->dropdown('aco[]')
->label(__('ACO').': '.help::hint('aco'))
->rules('required')
->options(Aco_Model::get_actions())
->multiple('multiple')
->size(20);
$aro_group_model = new Aro_group_Model();
$aro_groups = $aro_group_model->find_all();
$arr_aro_groups = array();
foreach ($aro_groups as $aro_group)
$arr_aro_groups[$aro_group->id] = $aro_group->name;
$form->dropdown('aro_group[]')
->label(__('ARO groups').': '.help::hint('aro_groups'))
->rules('required')
->options($arr_aro_groups)
->multiple('multiple')
->size(20);
$axo_model = new Axo_Model();
$axos = $axo_model->find_all();
$arr_axos = array();
foreach ($axos as $axo)
$arr_axos[$axo->id] = $axo->name.' ('.$axo->section_value.')';
$form->dropdown('axo[]')
->label(__('AXO').': '.help::hint('axo'))
->rules('required')
->options($arr_axos)
->multiple('multiple')
->size(20);
$form->submit('submit')
->value(__('Add'));
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
$aco = (isset($_POST["aco"])) ? $_POST["aco"] : array();
$aro_groups = (isset($_POST["aro_group"])) ? $_POST["aro_group"] : array();
$axo = (isset($_POST["axo"])) ? $_POST["axo"] : array();
$axo_model = new Axo_Model();
$axo = $axo_model->get_values_by_ids($axo);
$acl = new Acl_Model();
$acl->note = $form_data['description'];
$acl->save();
$acl->insert_aco($aco);
$acl->insert_aro_groups($aro_groups);
$acl->insert_axo($axo);
status::success('Access control rule has been successfully added.');
url::redirect('acl/show/'.$acl->id);
}
$headline = __('Add access control rule');
$breadcrumbs = breadcrumbs::add()
->link('acl/show_all', 'Access control rules',
$this->acl_check_view('Settings_Controller', 'access_rights'))
->text('Add new rule');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('form');
$view->content->form = $form;
$view->content->headline = $headline;
$view->render(TRUE);
}
/**
* Edits access control rule
*
* @author Michal Kliment
* @param integer $acl_id
*/
public function edit ($acl_id = NULL)
{
// check access
if (!$this->acl_check_edit('Settings_Controller', 'access_rights'))
Controller::Error(ACCESS);
// bad parameter
if (!$acl_id || !is_numeric($acl_id))
Controller::warning (PARAMETER);
$acl = new Acl_Model($acl_id);
// record doesn't exist
if (!$acl->id)
Controller::error(RECORD);
$form = new Forge(url::base(TRUE).url::current(TRUE));
$form->textarea('description')
->value($acl->note)
->rules('required')
->style('width:600px');
$sel_acos = array();
foreach ($acl->get_acos() as $aco)
$sel_acos[] = $aco->value;
$form->dropdown('aco[]')
->label(__('ACO').': '.help::hint('aco'))
->rules('required')
->options(Aco_Model::get_actions())
->selected($sel_acos)
->multiple('multiple')
->size(20);
$aro_group_model = new Aro_group_Model();
$aro_groups = $aro_group_model->find_all();
$arr_aro_groups = array();
foreach ($aro_groups as $aro_group)
$arr_aro_groups[$aro_group->id] = $aro_group->name;
$sel_aro_groups = array();
foreach ($acl->get_aro_groups() as $aro_group)
$sel_aro_groups[] = $aro_group->id;
$form->dropdown('aro_group[]')
->label(__('ARO groups').': '.help::hint('aro_groups'))
->rules('required')
->options($arr_aro_groups)
->selected($sel_aro_groups)
->multiple('multiple')
->size(20);
$axo_model = new Axo_Model();
$axos = $axo_model->find_all();
$arr_axos = array();
foreach ($axos as $axo)
$arr_axos[$axo->id] = $axo->name.' ('.$axo->section_value.')';
$sel_axos = array();
foreach ($acl->get_axos() as $axo)
$sel_axos[] = $axo->id;
$form->dropdown('axo[]')
->label(__('AXO').': '.help::hint('axo'))
->rules('required')
->options($arr_axos)
->selected($sel_axos)
->multiple('multiple')
->size(20);
$form->submit('submit')
->value(__('Update'));
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
$aco = (isset($_POST["aco"])) ? $_POST["aco"] : array();
$aro_groups = (isset($_POST["aro_group"])) ? $_POST["aro_group"] : array();
$axo = (isset($_POST["axo"])) ? $_POST["axo"] : array();
$axo_model = new Axo_Model();
$axo = $axo_model->get_values_by_ids($axo);
$acl->note = $form_data['description'];
$acl->save();
$acl->clean_rule();
$acl->insert_aco($aco);
$acl->insert_aro_groups($aro_groups);
$acl->insert_axo($axo);
status::success('Access control rule has been successfully updated.');
url::redirect('acl/show/'.$acl->id);
}
$headline = __('Edit access control rule');
$breadcrumbs = breadcrumbs::add()
->link('acl/show_all', 'Access control rules',
$this->acl_check_view('Settings_Controller', 'access_rights'))
->link('acl/show/'.$acl->id, 'ID '.$acl->id,
$this->acl_check_view('Settings_Controller', 'access_rights'))
->text('Edit');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $headline;
$view->content = new View('form');
$view->content->form = $form;
$view->content->headline = $headline;
$view->render(TRUE);
}
/**
* Deletes access control rule
*
* @author Michal Kliment
* @param integer $acl_id
*/
public function delete ($acl_id = NULL)
{
// check access
if (!$this->acl_check_edit('Settings_Controller', 'access_rights'))
Controller::Error(ACCESS);
// bad parameter
if (!$acl_id || !is_numeric($acl_id))
Controller::warning(PARAMETER);
$acl = new Acl_Model($acl_id);
// record doesn't exist
if (!$acl->id)
Controller::error(RECORD);
// clean ACL
$acl->clean_rule();
// successfully deleted
if ($acl->delete())
status::success('Access control rule has been successfully deleted.');
else
status::error('Error - cannot delete access rule.');
url::redirect('acl/show_all');
}
}
?>
application/controllers/address_points.php
<?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 address points actions.
*
* @package Controller
*/
class Address_points_Controller extends Controller
{
const METHOD_GOOGLE = 1;
/**
* Index redirects to show all
*/
public function index()
{
url::redirect('address_points/show_all');
}
/**
* Function shows list of all address points.
*
* @author Michal Kliment
* @param $limit_results
* @param $order_by
* @param $order_by_direction
* @param $page_word
* @param $page
*/
public function show_all(
$member_id = 0, $limit_results = 50, $order_by = 'items_count',
$order_by_direction = 'DESC', $page_word = null, $page = 1)
{
// access rights
if (!$this->acl_check_view(get_class($this), 'address_point'))
Controller::error(ACCESS);
// gets new selector
if (is_numeric($this->input->get('record_per_page')))
$limit_results = (int) $this->input->get('record_per_page');
// parameters control
$allowed_order_type = array
(
'id', 'name', 'street', 'street_number', 'town', 'quarter',
'zip_code', 'gps', 'items_count'
);
// order by check
if (!in_array(strtolower($order_by), $allowed_order_type))
$order_by = 'id';
// order by direction check
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
$town_model = new Town_Model();
$street_model = new Street_Model();
$filter_form = new Filter_form('ap');
$filter_form->add('name')
->callback('json/address_point_name');
$filter_form->add('country_name')
->label('Country')
->callback('json/country_name');
$filter_form->add('street')
->type('select')
->values(
array_unique(
$street_model->select_list('street', 'street')
)
);
$filter_form->add('street_number')
->type('number');
$filter_form->add('town')
->type('select')
->values(
array_unique(
$town_model->select_list('town', 'town')
)
);
$filter_form->add('quarter')
->callback('json/quarter_name');
$filter_form->add('zip_code')
->callback('json/zip_code');
$filter_form->add('gps')
->callback('json/gps');
$filter_form->add('items_count')
->type('number');
$address_point_model = new Address_point_Model();
$total_address_points = $address_point_model->count_all_address_points(
$member_id, $filter_form->as_sql()
);
// limit check
if (($sql_offset = ($page - 1) * $limit_results) > $total_address_points)
$sql_offset = 0;
$query = $address_point_model->get_all_address_points(
$sql_offset, (int)$limit_results, $order_by, $order_by_direction,
$member_id, $filter_form->as_sql()
);
// it creates grid to view all address points
$grid = new Grid('address_points', '', array
(
'current' => $limit_results,
'selector_increace' => 50,
'selector_min' => 50,
'selector_max_multiplier' => 10,
'base_url' => Config::get('lang').'/address_points/show_all/'.
$member_id.'/'.$limit_results.'/'.$order_by.'/'.$order_by_direction,
'uri_segment' => 'page',
'total_items' => $total_address_points,
'items_per_page' => $limit_results,
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results,
'filter' => $filter_form,
'variables' => $member_id.'/',
'url_array_ofset' => 1,
));
$grid->add_new_button('address_points/add', __('Add address point'));
$grid->add_new_button(
'address_points/autocomplete_gps',
__('Automatically fill in GPS coordinates')
);
/*$grid->add_new_button(
'address_points/import',
__('Import addresses')
);*/
$grid->order_field('id')
->label('ID');
$grid->order_field('name');
$grid->order_field('country_name')
->label('Country');
$grid->order_field('street');
$grid->order_field('street_number');
$grid->order_field('town');
$grid->order_field('quarter');
$grid->order_field('zip_code');
$grid->order_callback_field('gps')
->callback('callback::gps_field');
$grid->order_callback_field('items_count')
->callback('callback::items_count_field');
$actions = $grid->grouped_action_field();
if ($this->acl_check_view(get_class($this), 'address_point'))
{
$actions->add_action('id')
->icon_action('show')
->url('address_points/show');
}
if ($this->acl_check_edit(get_class($this), 'address_point'))
{
$actions->add_action('id')
->icon_action('edit')
->url('address_points/edit');
}
if ($this->acl_check_delete(get_class($this), 'address_point'))
{
$actions->add_action('id')
->icon_action('delete')
->url('address_points/delete')
->class('delete_link');
}
$grid->datasource($query);
$links = array();
$links[] = __('Address points');
$links[] = html::anchor('towns', __('Towns'));
$links[] = html::anchor('streets', __('Streets'));
$members = array
(
NULL => '----- '.__('Select member').' -----'
) + arr::from_objects(ORM::factory('member')->get_all_members_to_dropdown());
// form to group by type
$form = new Forge(url::base(TRUE).url::current(TRUE));
$form->dropdown('member_id')
->options($members)
->selected($member_id);
$form->submit('submit');
if ($form->validate())
{
url::redirect('address_points/show_all/'.$form->member_id->value);
}
// view
$view = new View('main');
$view->breadcrumbs = __('Address points');
$view->title = __('List of all address points');
$view->content = new View('show_all');
$view->content->submenu = implode(' | ',$links);
$view->content->headline = __('List of all address points');
$view->content->form = $form;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Function shows address point detail.
*
* @author Michal Kliment
* @param integer $address_point_id id of address point to show
*/
public function show($address_point_id = NULL)
{
// bad parameter
if (!$address_point_id)
Controller::warning(PARAMETER);
$ap = new Address_point_Model($address_point_id);
// address point doesn't exist
if (!$ap->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_view(get_class($this), 'address_point'))
Controller::error(ACCESS);
$gps = "";
if (! empty ($ap->gps))
{
$gps_result = $ap->get_gps_coordinates($ap->id);
if (! empty($gps_result))
{
$gps = gps::degrees($gps_result->gpsx, $gps_result->gpsy, true);
}
}
// finds all members on this address
$members = $ap->get_all_members();
$members_grid = new Grid('members', null, array
(
'separator' => '<br /><br />',
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($members)
));
$members_grid->field('member_id')
->label('ID');
$members_grid->link_field('member_id')
->link('members/show', 'member_name');
$members_grid->callback_field('type')
->callback('callback::address_point_member_field');
$members_grid->datasource($members);
// finds all devices on this address
$devices = $ap->get_all_devices();
$devices_grid = new Grid('devices', null,array
(
'separator' => '<br /><br />',
'use_paginator' => false,
'use_selector' => false,
'total_items' => count($devices)
));
$devices_grid->field('device_id')
->label('ID');
$devices_grid->callback_field('device_id')
->label(__('Device'))
->callback('callback::device_field');
$devices_grid->link_field('user_id')
->link('users/show', 'user_name')
->label('User');
$devices_grid->link_field('member_id')
->link('members/show', 'member_name')
->label('Member');
$devices_grid->datasource($devices);
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('address_points/show_all', 'Address points',
$this->acl_check_view(get_class($this), 'address_point'))
->disable_translation()
->text($ap->__toString())
->html();
// view
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = __('Address point detail');
$view->content = new View('address_points/show');
$view->content->address_point = $ap;
$view->content->members_grid = $members_grid;
$view->content->devices_grid = $devices_grid;
$view->content->gps = $gps;
$view->content->gpsx = !empty($gps) ? $gps_result->gpsx : '';
$view->content->gpsy = !empty($gps) ? $gps_result->gpsy : '';
$view->content->lang = Config::get('lang');
$view->render(TRUE);
}
/**
* Function allow to add address point.
*
* @author Ondřej Fibich
*/
public function add()
{
// access rights
if (!$this->acl_check_new(get_class($this),'address_point'))
Controller::error(ACCESS);
// country
$arr_countries = ORM::factory('country')->select_list('id', 'country_name');
// streets
$arr_streets = array
(
NULL => '----- '.__('without street').' -----'
) + ORM::factory('street')->select_list('id', 'street');
// towns
$arr_towns = array
(
NULL => '----- '.__('select town').' -----'
) + ORM::factory('town')->select_list_with_quater();
// creates new form
$form = new Forge('address_points/add/');
$form->dropdown('country_id')
->label('Country')
->rules('required')
->options($arr_countries)
->selected(Settings::get('default_country'))
->style('width:200px');
$form->dropdown('town_id')
->label('Town')
->rules('required')
->options($arr_towns)
->style('width:200px');
$form->dropdown('street_id')
->label('Street')
->options($arr_streets)
->style('width:200px');
$form->input('street_number')
->rules('length[1,50]');
$form->input('gpsx')
->label(__('GPS').' X:&nbsp;'.help::hint('gps_coordinates'))
->rules('gps');
$form->input('gpsy')
->label(__('GPS').' Y:&nbsp;'.help::hint('gps_coordinates'))
->rules('gps');
$form->submit('Add');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
$use_gps = !empty($form_data['gpsx']) && !empty($form_data['gpsy']);
$address_point_model = new Address_point_Model();
// check if address point just exist
$address_point = $address_point_model->get_address_point(
$form_data['country_id'], $form_data['town_id'],
$form_data['street_id'], $form_data['street_number'],
$form_data['gpsx'], $form_data['gpsy']
);
$issaved = TRUE;
// address point is already in database?
if ($address_point->id)
{
// check if it is not same as origin
status::warning('Address point already in database.');
$issaved = FALSE;
}
else
{
// address point doesn't exist
$issaved = $issaved && $address_point->save();
// save GPS if it is set
if ($use_gps)
{
$gpsx = doubleval($form_data["gpsx"]);
$gpsy = doubleval($form_data["gpsy"]);
if (gps::is_valid_degrees_coordinate($form->gpsx->value))
{
$gpsx = gps::degrees2real($form->gpsx->value);
}
if (gps::is_valid_degrees_coordinate($form->gpsy->value))
{
$gpsy = gps::degrees2real($form->gpsy->value);
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff