Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2102

Přidáno uživatelem Ondřej Fibich před asi 11 roky(ů)

Novinky:
- refs #563: Domumentace AXO:
- vytvoreni struktury XMl dokumentu, ktery bude pouzivany jako databaze (XML soubor + DTD)
- skript v perlu, ktery je schopny vygenerovat zakladni podobu dokumenace

Zobrazit rozdíly:

freenetis/branches/1.1/application/vendors/axo_doc/axo_doc.dtd
<?xml version='1.0' encoding='UTF-8'?>
<!--
DTD for AXO documentation file.
@author Ondřej Fibich
@version 1.0
-->
<!--
An example how to use this DTD from your XML document:
<?xml version="1.0"?>
<!DOCTYPE axoDocumentation SYSTEM "axo_doc.dtd">
<axoDocumentation>
...
</axoDocumentation>
-->
<!--- Root elements that contains objects. -->
<!ELEMENT axoDocumentation (object)*>
<!--- Object that represents a class of the given type. -->
<!ELEMENT object (method)*>
<!ATTLIST object
type (controller|helper|library) #REQUIRED
name CDATA #REQUIRED
hide (true|false) "false"
>
<!--- Method of the object -->
<!ELEMENT method (axo)*>
<!ATTLIST method
name CDATA #REQUIRED
hide (true|false) "false"
>
<!--- An AXO calll -->
<!ELEMENT axo (comment)*>
<!ATTLIST axo
own (true|false) #REQUIRED
value CDATA #REQUIRED
section CDATA #REQUIRED
action (edit|new|delete|confirm|view) #REQUIRED
usage_type (unknown|access|breadcrumbs|links) #REQUIRED
>
<!-- Comment in a defines language for the AXo call -->
<!ELEMENT comment EMPTY>
<!ATTLIST comment
lang (en|cs) #REQUIRED
>
freenetis/branches/1.1/application/vendors/axo_doc/axo_doc.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE axoDocumentation SYSTEM "axo_doc.dtd">
<axoDocumentation>
<object name="accounts" type="controller">
<method name="__construct"></method>
<method name="index"></method>
<method name="show_all">
<!-- 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');
// Create filter form
$filter_form = new Filter_form();
$filter_form->add('id')
->table('aa')
->label('Account');
$filter_form->add('name')
->table('aa')
->label('Account name');
$filter_form->add('datetime')
->label('Balance date')
->type('date');
// gets grid settings
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('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_form->as_sql(array
(
'id', 'name'
)));
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_form->as_sql(array(
'id', 'name'
)),
$filter_form->as_sql(array('datetime'))
);
}
else
{
$account_model = new Account_Model();
$total_accounts = $account_model->get_accounts_count($filter_form->as_sql(array
(
'id', 'name'
)),
$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_form->as_sql(array(
'id', 'name'
)),
$filter_form->as_sql(array('datetime')),
$group
);
}
// 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,
'filter' => $filter_form,
'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 -->
<axo section="Accounts_Controller" value="accounts" action="view" own="false" usage_type="unknown"></axo>
<axo section="Accounts_Controller" value="accounts" action="edit" own="false" usage_type="unknown"></axo>
<axo section="Accounts_Controller" value="accounts" action="new" own="false" usage_type="unknown"></axo>
<axo section="Accounts_Controller" value="transfers" action="view" own="false" usage_type="unknown"></axo>
<axo section="Accounts_Controller" value="accounts" action="edit" own="false" usage_type="unknown"></axo>
</method>
<method name="add_project">
<!-- 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 -->
<axo section="Accounts_Controller" value="accounts" action="new" own="false" usage_type="unknown"></axo>
<axo section="Accounts_Controller" value="accounts" action="view" own="false" usage_type="unknown"></axo>
</method>
<method name="edit">
<!-- 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 -->
<axo section="Accounts_Controller" value="accounts" action="edit" own="false" usage_type="unknown"></axo>
<axo section="Accounts_Controller" value="accounts" action="view" own="false" usage_type="unknown"></axo>
</method>
<method name="recalculate_account_balances">
<!-- 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');
}
/**
* Recalculates all fees of account
*
* @author Michal Kliment
* @param type $account_id
*/
public -->
<axo section="Accounts_Controller" value="accounts" action="edit" own="false" usage_type="unknown"></axo>
</method>
<method name="recalculate_fees">
<!-- recalculate_fees($account_id = NULL)
{
// bad parameter
if (!$account_id)
Controller::warning (PARAMETER);
$account = new Account_Model($account_id);
// account doesn't exist
if (!$account->id)
Controller::error (RECORD);
// acccess control
if (!$this->acl_check_edit('Accounts_Controller', 'accounts'))
Controller::error (ACCESS);
try
{
// recalculates entrance fees
$entrance_fee_stats = self::recalculate_entrance_fees($account->id);
// recalculates member fees
$member_fee_stats = self::recalculate_member_fees($account->id);
// recalculates device fees
$device_fee_stats = self::recalculate_device_fees($account->id);
$deleted_transfers_count = $entrance_fee_stats['deleted'] + $member_fee_stats['deleted'] + $device_fee_stats['deleted'];
$created_transfers_count = $entrance_fee_stats['created'] + $member_fee_stats['created'] + $device_fee_stats['created'];
status::success(
'Fees have been successfully recalculated, %d deleted '.
'transfers, %d created new transfers.',
TRUE, array
(
0 => $deleted_transfers_count,
1 => $created_transfers_count
)
);
}
catch (Exception $e)
{
status::error('Error - Cannot recalculate fees', $e);
Log::add_exception($e);
}
$this->redirect('transfers/show_by_account/'.$account->id);
}
/**
* Recalculates entrance fees of account
*
* @author Michal Kliment
* @param type $account_id
* @return type
* @throws Exception
*/
public static -->
<axo section="Accounts_Controller" value="accounts" action="edit" own="false" usage_type="unknown"></axo>
</method>
<method name="recalculate_entrance_fees"></method>
<method name="recalculate_member_fees"></method>
<method name="recalculate_device_fees"></method>
</object>
<object name="acl" type="controller">
<method name="index"></method>
<method name="show_all">
<!-- show_all(
$limit_results = 100, $order_by = 'id',
$order_by_direction = 'asc',
$page_word = 'page', $page = 1)
{
// check access
if (!$this->acl_check_view('Acl_Controller', 'acl'))
Controller::Error(ACCESS);
// gets new selector
if (is_numeric($this->input->post('record_per_page')))
$limit_results = (int) $this->input->post('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';
$filter_form = new Filter_form('a');
$filter_form->add('note');
$filter_form->add('aco_value')
->label('ACO')
->type('select')
->values(Aco_Model::get_actions());
$filter_form->add('aro_group_id')
->label('ARO group')
->type('select')
->values(Aro_group_Model::get_groups());
$filter_form->add('axo_section_value')
->label('AXO section')
->type('select')
->values(Axo_Model::get_section_values());
$filter_form->add('axo_value')
->label('AXO value')
->type('select')
->values(Axo_Model::get_values());
$acl_model = new Acl_Model();
$total_rules = $acl_model->count_all_rules($filter_form->as_sql());
// 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,
$filter_form->as_sql()
);
$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
));
if ($this->acl_check_new('Acl_Controller', 'acl'))
{
$grid->add_new_button('acl/add', __('Add new rule'));
}
$grid->order_field('id')
->label(__('ID'));
$grid->order_callback_field('note')
->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');
if ($this->acl_check_edit('Acl_Controller', 'acl'))
{
$actions->add_action('id')
->icon_action('edit')
->url('acl/edit');
}
if ($this->acl_check_delete('Acl_Controller', 'acl'))
{
$actions->add_action('id')
->icon_action('delete')
->url('acl/delete')
->class('delete_link');
}
$grid->datasource($rules);
if ($this->acl_check_view('Aro_groups_Controller', 'aro_group'))
{
$submenu = array();
$submenu[] = html::anchor('acl/show_all', __('Access control rules'));
$submenu[] = html::anchor('aro_groups/show_all', __('Access control groups of users'));
}
else
{
$submenu = NULL;
}
$view = new View('main');
$view->breadcrumbs = __('Access control rules');
$view->title = $headline;
$view->content = new View('show_all');
$this->sections = $submenu;
$view->content->current = 'acl/show_all';
$view->content->headline = $headline;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Shows access control rule
*
* @author Michal Kliment
* @param integer $acl_id
*/
public -->
<axo section="Acl_Controller" value="acl" action="view" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="new" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="edit" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="delete" own="false" usage_type="unknown"></axo>
<axo section="Aro_groups_Controller" value="aro_group" action="view" own="false" usage_type="unknown"></axo>
</method>
<method name="show">
<!-- show($acl_id = NULL)
{
// check access
if (!$this->acl_check_view('Acl_Controller', 'acl'))
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('Acl_Controller', 'acl'))
->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 -->
<axo section="Acl_Controller" value="acl" action="view" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="view" own="false" usage_type="unknown"></axo>
</method>
<method name="add">
<!-- add()
{
// check access
if (!$this->acl_check_new('Acl_Controller', 'acl'))
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('Acl_Controller', 'acl'))
->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 -->
<axo section="Acl_Controller" value="acl" action="new" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="view" own="false" usage_type="unknown"></axo>
</method>
<method name="edit">
<!-- edit($acl_id = NULL)
{
// check access
if (!$this->acl_check_edit('Acl_Controller', 'acl'))
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('Acl_Controller', 'acl'))
->link('acl/show/'.$acl->id, 'ID '.$acl->id,
$this->acl_check_view('Acl_Controller', 'acl'))
->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 -->
<axo section="Acl_Controller" value="acl" action="edit" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="view" own="false" usage_type="unknown"></axo>
<axo section="Acl_Controller" value="acl" action="view" own="false" usage_type="unknown"></axo>
</method>
<method name="delete">
<!-- delete($acl_id = NULL)
{
// check access
if (!$this->acl_check_delete('Acl_Controller', 'acl'))
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');
}
}
-->
<axo section="Acl_Controller" value="acl" action="delete" own="false" usage_type="unknown"></axo>
</method>
</object>
<object name="address_points" type="controller">
<method name="index"></method>
<method name="show_all"></method>
<method name="show"></method>
<method name="add"></method>
<method name="edit"></method>
<method name="delete"></method>
<method name="get_gps_by_address"></method>
<method name="get_geocode_from_google"></method>
<method name="autocomplete_gps"></method>
</object>
<object name="allowed_subnets" type="controller">
<method name="show_by_member">
<!-- show_by_member($member_id = NULL)
{
// bad parameter
if (!$member_id || !is_numeric($member_id))
Controller::warning(PARAMETER);
$member = new Member_Model($member_id);
// record doesn't exist
if (!$member->id || $member->id == 1)
Controller::error(RECORD);
// access control
if (!$this->acl_check_view('Allowed_subnets_Controller', 'allowed_subnet', $member->id))
Controller::error(ACCESS);
// finds all allowed subnets of member
$allowed_subnet_model = new Allowed_subnet_Model();
$allowed_subnets = $allowed_subnet_model
->get_all_allowed_subnets_by_member($member->id, 'cidr');
// grid
$grid = new Grid('members', null, array
(
'separator' => '<br /><br />',
'use_paginator' => false,
'use_selector' => false,
));
$grid->add_new_button(
'allowed_subnets/add/' . $member->id,
__('Add new subnet'),
array
(
'title' => __('Add new subnet'),
'class' => 'popup_link'
)
);
$grid->link_field('subnet_id')
->link('subnets/show', 'subnet_name');
$grid->callback_field('cidr_address')
->label(__('Network address'))
->callback('callback::cidr_field');
$param = '';
if ($allowed_subnet_model->count_all_disabled_allowed_subnets_by_member($member->id))
{
$param = 'allowed_subnets/change/';
}
$grid->callback_field('enabled')
->callback('callback::enabled_field', $param)
->class('center');
$grid->grouped_action_field()
->add_action('id')
->icon_action('delete')
->url('allowed_subnets/delete')
->class('delete_link');
// load records
$grid->datasource($allowed_subnets);
// breadcrums
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/' . $member->id, "ID $member->id - $member->name",
$this->acl_check_view('Members_Controller', 'members', $member->id))
->enable_translation()
->text('Allowed subnets')
->html();
// view
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = __('Allowed subnets of member') . ' ' . $member->name;
$view->content = new View('allowed_subnets/show_by_member');
$view->content->member_id = $member->id;
$view->content->count = $member->allowed_subnets_count->count;
$view->content->headline = __('Allowed subnets of member') . ' ' . $member->name;
$view->content->table = $grid;
$view->render(TRUE);
}
/**
* Adds new allowed subnet to member
*
* @author Michal Kliment
* @param integer $member_id
*/
public -->
<axo section="Allowed_subnets_Controller" value="allowed_subnet" action="view" own="true" usage_type="unknown"></axo>
<axo section="Members_Controller" value="members" action="view" own="false" usage_type="unknown"></axo>
<axo section="Members_Controller" value="members" action="view" own="true" usage_type="unknown"></axo>
</method>
<method name="add">
<!-- add($member_id = NULL)
{
// bad parameter
if (!$member_id || !is_numeric($member_id))
Controller::warning(PARAMETER);
$member = new Member_Model($member_id);
// member doesn't exist
if (!$member->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_new('Allowed_subnets_Controller', 'allowed_subnet', $member->id))
Controller::error(ACCESS);
$subnet_model = new Subnet_Model();
// finds all subnets without allowed subnets of member
$subnets = $subnet_model->get_all_subnets_without_allowed_subnets_of_member($member->id);
$arr_subnets = arr::merge(array
(
NULL => '- ' . __('select subnet') . ' -'
), arr::from_objects($subnets));
// selected subnet
$current_subnet = $subnet_model->get_subnet_without_allowed_subnets_of_member_by_ip_address(
$member->id, server::remote_addr()
);
$selected = ($current_subnet && $current_subnet->id) ? $current_subnet->id : 0;
// from
$form = new Forge();
$form->dropdown('subnet_id')
->label(__('Subnet') . ':')
->rules('required')
->options($arr_subnets)
->selected($selected)
->add_button('subnets');
$form->submit('Add');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
$allowed_subnet = new Allowed_subnet_Model();
$allowed_subnet->member_id = $member->id;
$allowed_subnet->subnet_id = $form_data['subnet_id'];
$allowed_subnet->enabled = 1;
if ($allowed_subnet->save())
{
status::success('Subnet has been successfully saved.');
self::update_enabled($member->id);
}
$this->redirect('allowed_subnets/show_by_member/' . $member->id);
}
else
{
// bread crumbs
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->link('members/show/' . $member->id, "ID $member->id - $member->name",
$this->acl_check_view('Members_Controller', 'members', $member->id))
->enable_translation()
->link('allowed_subnets/show_by_member/' . $member->id, 'Allowed subnets')
->text('Add new subnet')
->html();
$title = __('Add new allowed subnet to member') . ' ' . $member->name;
// view
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $title;
$view->content = new View('form');
$view->content->headline = $title;
$view->content->form = $form->html();
$view->render(TRUE);
}
}
/**
* Deletes subnet from allowed subnets of member
*
* @author Michal Kliment
* @param integer $allowed_subnet_id
*/
public -->
<axo section="Allowed_subnets_Controller" value="allowed_subnet" action="new" own="true" usage_type="unknown"></axo>
<axo section="Members_Controller" value="members" action="view" own="false" usage_type="unknown"></axo>
<axo section="Members_Controller" value="members" action="view" own="true" usage_type="unknown"></axo>
</method>
<method name="delete">
<!-- delete($allowed_subnet_id = NULL)
{
// bad parameter
if (!$allowed_subnet_id || !is_numeric($allowed_subnet_id))
Controller::warning(PARAMETER);
$allowed_subnet = new Allowed_subnet_Model($allowed_subnet_id);
// record doesn't exist
if (!$allowed_subnet->id)
Controller::error(RECORD);
$member_id = $allowed_subnet->member_id;
// access control
if (!$this->acl_check_delete('Allowed_subnets_Controller', 'allowed_subnet', $member_id))
Controller::error(ACCESS);
// success
if ($allowed_subnet->delete())
{
status::success('Subnet has been successfully deleted.');
self::update_enabled($member_id);
}
$this->redirect(Path::instance()->previous());
}
/**
* Toggle state of allowed subnet of member (from disable to enabled and from enabled to disable)
*
* @author Michal Kliment
* @param integer $allowed_subnet_id
*/
public -->
<axo section="Allowed_subnets_Controller" value="allowed_subnet" action="delete" own="true" usage_type="unknown"></axo>
</method>
<method name="change">
<!-- change($allowed_subnet_id = NULL)
{
// bad parameter
if (!$allowed_subnet_id || !is_numeric($allowed_subnet_id))
Controller::warning(PARAMETER);
$allowed_subnet = new Allowed_subnet_Model($allowed_subnet_id);
// record doesn't exist
if (!$allowed_subnet->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_edit('Allowed_subnets_Controller', 'allowed_subnet', $allowed_subnet->member->id))
Controller::error(ACCESS);
$allowed_subnet->enabled = !$allowed_subnet->enabled;
$allowed_subnet->save();
if ($allowed_subnet->enabled)
{
status::success('Subnet has been successfully enabled.');
self::update_enabled($allowed_subnet->member_id);
}
else
{
status::success('Subnet has been successfully disabled.');
self::update_enabled($allowed_subnet->member_id, NULL, array($allowed_subnet->subnet_id));
}
$this->redirect(Path::instance()->previous());
}
/**
* Updates states of allowed subnets of member
*
* @author Michal Kliment
* @param integer $member_id
* @param string | array $to_enable
* @param string | array $to_disable
* @param string | array $to_remove
* @param boolean $thow_ex_on_error Trow an exception if an error occure?
* @return boolean State of operation.
*/
public static -->
<axo section="Allowed_subnets_Controller" value="allowed_subnet" action="edit" own="true" usage_type="unknown"></axo>
</method>
<method name="update_enabled"></method>
</object>
<object name="allowed_subnets_counts" type="controller">
<method name="edit">
<!-- edit($member_id = NULL)
{
// bad parameter
if (!$member_id || !is_numeric($member_id))
Controller::warning(PARAMETER);
$member = new Member_Model($member_id);
// member doesn't exist
if (!$member->id || $member->id == 1)
Controller::error(RECORD);
// access control
if (!$this->acl_check_edit('Allowed_subnets_Controller', 'allowed_subnet', $member_id))
Controller::error(ACCESS);
$form = new Forge(url::base(TRUE) . url::current(TRUE));
$form->input('allowed_subnets_count')
->label(__('Count of allowed subnets')
. ': ' . help::hint('allowed_subnets_count'))
->rules('valid_numeric')
->value($member->allowed_subnets_count->count);
$form->submit('Edit');
// form is validate
if ($form->validate())
{
$form_data = $form->as_array();
try
{
$member->transaction_start();
// posted value is not null
if ($form_data['allowed_subnets_count'])
{
// count of allowed subnets is not set
if ($member->allowed_subnets_count->id == 0)
{
$allowed_subnets_count = new Allowed_subnets_count_Model();
$allowed_subnets_count->member_id = $member->id;
$allowed_subnets_count->count = $form_data['allowed_subnets_count'];
$allowed_subnets_count->save_throwable();
}
// count of allowed subnets is already set
else
{
$member->allowed_subnets_count->count = $form_data['allowed_subnets_count'];
$member->allowed_subnets_count->save_throwable();
}
}
// delete null count
else if ($member->allowed_subnets_count)
{
$member->allowed_subnets_count->delete_throwable();
}
Allowed_subnets_Controller::update_enabled($member->id);
$member->transaction_commit();
status::success('Count of allowed subnets has been successfully updated.');
}
catch (Exception $e)
{
$member->transaction_rollback();
Log::add_exception($e);
status::error('Error - Cannot update count of allowed subnets', $e);
}
$this->redirect('allowed_subnets/show_by_member/' . $member_id);
}
else
{
$title = __('Edit maximum count of allowed subnets of member') . ' ' . $member->name;
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff