Revize 2140
Přidáno uživatelem Ondřej Fibich před více než 11 roky(ů)
freenetis/branches/1.1/application/vendors/axo_doc/axo_doc.xml | ||
---|---|---|
<axo usage_type="access" section="Accounts_Controller" value="invoices" action="view" own="false"></axo>
|
||
</method>
|
||
</object>
|
||
<object name="fees" type="controller">
|
||
<object name="fees" type="controller"
|
||
comment-en="Fees - tarifs for members fees"
|
||
comment-cs="Poplatky - tarify pro členské příspěvky">
|
||
<method name="__construct"></method>
|
||
<method name="index"></method>
|
||
<method name="show_all">
|
||
<!-- show_all(
|
||
$limit_results = 200, $order_by = 'id', $order_by_direction = 'ASC')
|
||
{
|
||
// check if logged user have access right to view all fees
|
||
if (!$this->acl_check_view('Fees_Controller', 'fees'))
|
||
Controller::Error(ACCESS);
|
||
|
||
// to-do - pagination
|
||
// get new selector
|
||
if (is_numeric($this->input->post('record_per_page')))
|
||
$limit_results = (int) $this->input->post('record_per_page');
|
||
|
||
$allowed_order_type = array('id', 'type', 'fee', 'from', 'to');
|
||
|
||
if (!in_array(strtolower($order_by), $allowed_order_type))
|
||
$order_by = 'id';
|
||
|
||
if (strtolower($order_by_direction) != 'desc')
|
||
$order_by_direction = 'asc';
|
||
|
||
$fee_model = new Fee_Model();
|
||
$fees = $fee_model->get_all_fees($order_by, $order_by_direction);
|
||
$total_fees = $fee_model->count_all();
|
||
|
||
// create grid
|
||
$grid = new Grid('fees', '', array
|
||
(
|
||
'use_paginator' => true,
|
||
'use_selector' => true,
|
||
'current' => $limit_results,
|
||
'selector_increace' => 200,
|
||
'selector_min' => 200,
|
||
'selector_max_multiplier' => 10,
|
||
'base_url' => Config::get('lang') . '/fees/show_all/'
|
||
. $limit_results . '/' . $order_by . '/' . $order_by_direction,
|
||
'uri_segment' => 'page',
|
||
'total_items' => $total_fees,
|
||
'items_per_page' => $limit_results,
|
||
'style' => 'classic',
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results
|
||
));
|
||
|
||
// add button for new translation
|
||
// check if logged user have access right to add new translation
|
||
if ($this->acl_check_new('Fees_Controller', 'fees'))
|
||
{
|
||
$grid->add_new_button('fees/add', __('Add new fee'));
|
||
}
|
||
|
||
// set grid fields
|
||
$grid->order_field('id');
|
||
|
||
$grid->order_field('type');
|
||
|
||
$grid->order_callback_field('name')
|
||
->callback(array($this, 'name_field'));
|
||
|
||
$grid->order_field('fee');
|
||
|
||
$grid->order_field('from')
|
||
->label(__('Date from'));
|
||
|
||
$grid->order_field('to')
|
||
->label(__('Date to'));
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
// check if logged user have access right to edit this enum types
|
||
if ($this->acl_check_edit('Fees_Controller', 'fees'))
|
||
{
|
||
$actions->add_conditional_action()
|
||
->icon_action('edit')
|
||
->condition('is_not_readonly')
|
||
->url('fees/edit');
|
||
}
|
||
|
||
// check if logged user have access right to delete this enum_types
|
||
if ($this->acl_check_delete('Fees_Controller', 'fees'))
|
||
{
|
||
$actions->add_conditional_action()
|
||
->icon_action('delete')
|
||
->condition('is_not_readonly')
|
||
->url('fees/delete')
|
||
->class('delete_link');
|
||
}
|
||
|
||
$grid->datasource($fees);
|
||
|
||
// create view for this template
|
||
$view = new View('main');
|
||
$view->title = __('Fees');
|
||
$view->breadcrumbs = __('Fees');
|
||
$view->content = new View('show_all');
|
||
$view->content->table = $grid;
|
||
$view->content->headline = __('Fees');
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Adds new enum type
|
||
*
|
||
* @author Michal Kliment
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="new" own="false"></axo>
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="edit" own="false"></axo>
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="delete" own="false"></axo>
|
||
<axo usage_type="access" section="Fees_Controller" value="fees" action="view" own="false"></axo>
|
||
<axo usage_type="links" section="Fees_Controller" value="fees" action="new" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Fees_Controller" value="fees" action="edit" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Fees_Controller" value="fees" action="delete" own="false"></axo>
|
||
</method>
|
||
<method name="add">
|
||
<!-- add($fee_type_id = NULL)
|
||
{
|
||
// access control
|
||
if (!$this->acl_check_new('Fees_Controller', 'fees'))
|
||
Controller::error(ACCESS);
|
||
|
||
if ($fee_type_id && is_numeric($fee_type_id))
|
||
{
|
||
$enum_type_model = new Enum_type_Model();
|
||
$fee_type = $enum_type_model->where(array
|
||
(
|
||
'id' => $fee_type_id,
|
||
'type_id' => Enum_type_Model::FEE_TYPE_ID)
|
||
)->find();
|
||
|
||
if (!$fee_type || !$fee_type->id)
|
||
Controller::error(RECORD);
|
||
|
||
$enum_types = array($fee_type->id => $enum_type_model->get_value($fee_type->id));
|
||
}
|
||
else
|
||
{
|
||
$enum_type_name_model = new Enum_type_name_Model();
|
||
$enum_type_name = $enum_type_name_model->where('type_name', 'Fees types')->find();
|
||
|
||
$enum_type_model = new Enum_type_Model();
|
||
$enum_types = $enum_type_model->get_values($enum_type_name->id);
|
||
}
|
||
|
||
$form = array
|
||
(
|
||
'name' => '',
|
||
'fee' => 0,
|
||
'from' => array
|
||
(
|
||
'day' => date('j'),
|
||
'month' => date('n'),
|
||
'year' => date('Y')
|
||
),
|
||
'to' => array
|
||
(
|
||
'day' => date('j'),
|
||
'month' => date('n'),
|
||
'year' => date('Y')
|
||
),
|
||
'type_id' => 1
|
||
);
|
||
|
||
$errors = array
|
||
(
|
||
'fee' => '',
|
||
'from' => '',
|
||
'to' => '',
|
||
'type_id' => ''
|
||
);
|
||
|
||
|
||
$days = array();
|
||
for ($i = 1; $i <= 31; $i++)
|
||
$days[$i] = $i;
|
||
|
||
$months = array();
|
||
for ($i = 1; $i <= 12; $i++)
|
||
$months[$i] = $i;
|
||
|
||
$years = array();
|
||
for ($i = date('Y') - 100; $i <= date('Y') + 100; $i++)
|
||
$years[$i] = $i;
|
||
|
||
|
||
if ($_POST)
|
||
{
|
||
$post = new Validation($_POST);
|
||
$post->add_rules('fee', 'required', 'numeric');
|
||
|
||
$post->add_rules('from', array('valid', 'date'));
|
||
$post->add_rules('to', array('valid', 'date'));
|
||
|
||
// new system is not restricted on overlapping intervals in global scale
|
||
// overlapping will be checked individually with each member
|
||
$post->add_callbacks('type_id', array($this, 'valid_interval'));
|
||
|
||
if ($post->validate())
|
||
{
|
||
$fee = new Fee_Model();
|
||
$fee->type_id = $post->type_id;
|
||
$fee->name = $post->name;
|
||
$fee->fee = $post->fee;
|
||
$fee->from = date::round_month(
|
||
$post->from['day'],
|
||
$post->from['month'],
|
||
$post->from['year']
|
||
);
|
||
$fee->to = date::round_month(
|
||
$post->to['day'],
|
||
$post->to['month'],
|
||
$post->to['year'], TRUE
|
||
);
|
||
// clears form content
|
||
unset($form_data);
|
||
|
||
// for popup adding
|
||
if ($this->popup)
|
||
{
|
||
// save fee
|
||
$fee->save();
|
||
|
||
$fee_name = ($fee->name != '') ? "$fee->name - " : "";
|
||
$from = str_replace('-', '/', $fee->from);
|
||
$to = str_replace('-', '/', $fee->to);
|
||
$fee_name = "$fee_name$fee->fee " . __($this->settings->get('currency')) . " ($from-$to)";
|
||
}
|
||
else
|
||
{
|
||
// has fee been successfully saved?
|
||
if ($fee->save())
|
||
{
|
||
status::success('Fee has been successfully added');
|
||
}
|
||
else
|
||
{
|
||
status::error('Error - can\'t add new fee.');
|
||
}
|
||
|
||
// classic adding
|
||
url::redirect(url_lang::base() . 'fees/show_all');
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$form = arr::overwrite($form, $post->as_array());
|
||
$errors = arr::overwrite($errors, $post->errors('errors'));
|
||
}
|
||
}
|
||
|
||
// bread crumbs
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link('fees/show_all', 'Fees',
|
||
$this->acl_check_view('Fees_Controller', 'fees'))
|
||
->text('Add new fee');
|
||
|
||
// view for adding translation
|
||
$view = new View('main');
|
||
$view->title = __('Add new fee');
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('fees/add');
|
||
$view->content->name = $form['name'];
|
||
$view->content->fee = $form['fee'];
|
||
$view->content->from = $form['from'];
|
||
$view->content->to = $form['to'];
|
||
$view->content->type_id = $form['type_id'];
|
||
$view->content->errors = $errors;
|
||
$view->content->days = $days;
|
||
$view->content->months = $months;
|
||
$view->content->years = $years;
|
||
$view->content->types = $enum_types;
|
||
$view->content->fee_model = isset($fee) && $fee->id ? $fee : NULL;
|
||
$view->content->fee_name = isset($fee_name) ? $fee_name : NULL;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Edits fee
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $fee_id
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="new" own="false"></axo>
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="view" own="false"></axo>
|
||
<axo usage_type="access" section="Fees_Controller" value="fees" action="new" own="false"></axo>
|
||
<axo usage_type="breadcrumbs" section="Fees_Controller" value="fees" action="view" own="false"></axo>
|
||
</method>
|
||
<method name="edit">
|
||
<!-- edit($fee_id = NULL)
|
||
{
|
||
if (!$fee_id)
|
||
Controller::warning(PARAMETER);
|
||
|
||
// access control
|
||
if (!$this->acl_check_edit('Fees_Controller', 'fees'))
|
||
Controller::error(ACCESS);
|
||
|
||
$fee = new Fee_Model($fee_id);
|
||
|
||
// item is read only
|
||
if ($fee->readonly)
|
||
Controller::error(READONLY);
|
||
|
||
$enum_type_name_model = new Enum_type_name_Model();
|
||
$enum_type_name = $enum_type_name_model->where('type_name', 'Fees types')->find();
|
||
|
||
$enum_type_model = new Enum_type_Model();
|
||
$enum_types = $enum_type_model->get_values($enum_type_name->id);
|
||
|
||
$this->fee_id = $fee->id;
|
||
|
||
$form = array
|
||
(
|
||
'name' => $fee->name,
|
||
'fee' => $fee->fee,
|
||
'from' => array
|
||
(
|
||
'day' => (int) substr($fee->from, 8, 2),
|
||
'month' => (int) substr($fee->from, 5, 2),
|
||
'year' => (int) substr($fee->from, 0, 4)
|
||
),
|
||
'to' => array
|
||
(
|
||
'day' => (int) substr($fee->to, 8, 2),
|
||
'month' => (int) substr($fee->to, 5, 2),
|
||
'year' => (int) substr($fee->to, 0, 4)
|
||
),
|
||
'type_id' => $fee->type_id
|
||
);
|
||
|
||
$errors = array
|
||
(
|
||
'fee' => '',
|
||
'from' => '',
|
||
'to' => '',
|
||
'type_id' => ''
|
||
);
|
||
|
||
|
||
$days = array();
|
||
for ($i = 1; $i <= 31; $i++)
|
||
$days[$i] = $i;
|
||
|
||
$months = array();
|
||
for ($i = 1; $i <= 12; $i++)
|
||
$months[$i] = $i;
|
||
|
||
$years = array();
|
||
for ($i = date('Y') - 100; $i <= date('Y') + 100; $i++)
|
||
$years[$i] = $i;
|
||
|
||
|
||
if ($_POST)
|
||
{
|
||
$post = new Validation($_POST);
|
||
$post->add_rules('fee', 'required', 'numeric');
|
||
|
||
$post->add_rules('from', array('valid', 'date'));
|
||
$post->add_rules('to', array('valid', 'date'));
|
||
|
||
// new system is not restricted on overlapping intervals in global scale
|
||
// overlapping will be checked individually with each member
|
||
$post->add_callbacks('type_id', array($this, 'valid_interval'));
|
||
|
||
if ($post->validate())
|
||
{
|
||
$fee = new Fee_Model($fee_id);
|
||
$fee->type_id = $post->type_id;
|
||
$fee->name = $post->name;
|
||
$fee->fee = $post->fee;
|
||
$fee->from = date::round_month(
|
||
$post->from['day'],
|
||
$post->from['month'],
|
||
$post->from['year']
|
||
);
|
||
$fee->to = date::round_month(
|
||
$post->to['day'],
|
||
$post->to['month'],
|
||
$post->to['year']
|
||
);
|
||
// clears form content
|
||
unset($form_data);
|
||
// has fee been successfully saved?
|
||
if ($fee->save())
|
||
{
|
||
status::success('Fee has been successfully updated');
|
||
url::redirect(url_lang::base() . 'fees/show_all');
|
||
}
|
||
else
|
||
{
|
||
status::error('Error - cant edit fee.');
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$form = arr::overwrite($form, $post->as_array());
|
||
$errors = arr::overwrite($errors, $post->errors('errors'));
|
||
}
|
||
}
|
||
|
||
// bread crumbs
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link('fees/show_all', 'Fees',
|
||
$this->acl_check_view('Fees_Controller', 'fees'))
|
||
->text($fee->name . ' (' . $fee->id . ')')
|
||
->text('Edit fee');
|
||
|
||
// view for adding translation
|
||
$view = new View('main');
|
||
$view->title = __('Edit fee');
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('fees/edit');
|
||
$view->content->fee_id = $fee_id;
|
||
$view->content->name = $form['name'];
|
||
$view->content->fee = $form['fee'];
|
||
$view->content->from = $form['from'];
|
||
$view->content->to = $form['to'];
|
||
$view->content->type_id = $form['type_id'];
|
||
$view->content->errors = $errors;
|
||
$view->content->days = $days;
|
||
$view->content->months = $months;
|
||
$view->content->years = $years;
|
||
$view->content->types = $enum_types;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Deletes fee
|
||
*
|
||
* @author Michal Kliment
|
||
* @param ineteger $fee_id
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="edit" own="false"></axo>
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="view" own="false"></axo>
|
||
<axo usage_type="access" section="Fees_Controller" value="fees" action="edit" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Fees_Controller" value="fees" action="view" own="false"></axo>
|
||
</method>
|
||
<method name="delete">
|
||
<!-- delete($fee_id = NULL)
|
||
{
|
||
// wrong parameter
|
||
if (!$fee_id || !is_numeric($fee_id))
|
||
Controller::warning(PARAMETER);
|
||
|
||
// access control
|
||
if (!$this->acl_check_delete('Fees_Controller', 'fees'))
|
||
Controller::error(ACCESS);
|
||
|
||
$fee = new Fee_Model($fee_id);
|
||
|
||
// fee doesn't exist
|
||
if (!$fee->id)
|
||
Controller::error(RECORD);
|
||
|
||
// item is read only
|
||
if ($fee->readonly)
|
||
Controller::error(READONLY);
|
||
|
||
// fee is used on some tariffs
|
||
if ($fee->members_fees->count())
|
||
{
|
||
status::warning('Fee is used in some tariffs');
|
||
url::redirect(url_lang::base() . 'fees/show_all');
|
||
}
|
||
|
||
// success
|
||
if ($fee->delete())
|
||
{
|
||
status::success('Fee has been successfully deleted');
|
||
}
|
||
|
||
url::redirect(url_lang::base() . 'fees/show_all');
|
||
}
|
||
|
||
/**
|
||
* Checks overlapping of fee validity intervals.
|
||
*
|
||
* @param Validation $post
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Fees_Controller" value="fees" action="delete" own="false"></axo>
|
||
<axo usage_type="access" section="Fees_Controller" value="fees" action="delete" own="false"></axo>
|
||
</method>
|
||
</object>
|
||
<object name="filter_queries" type="controller">
|
||
<object name="filter_queries" type="controller"
|
||
comment-en="Management of stored filter queries of all grids (tables)"
|
||
comment-cs="Správa uložených dotazů všech gridů (tabulek)">
|
||
<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)
|
||
{
|
||
if (!$this->acl_check_view('Filter_queries_Controller', 'filter_queries'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$filter_query_model = new Filter_query_Model();
|
||
|
||
$filter_queries = $filter_query_model->get_all_queries();
|
||
|
||
$title = __('List of all filter queries');
|
||
|
||
// path to form
|
||
$path = Config::get('lang') . '/members/show_all/' . $limit_results . '/'
|
||
. $order_by . '/' . $order_by_direction.'/'.$page_word.'/'
|
||
. $page;
|
||
|
||
$grid = new Grid('members', null, array
|
||
(
|
||
'current' => $limit_results,
|
||
'selector_increace' => 200,
|
||
'selector_min' => 200,
|
||
'selector_max_multiplier' => 25,
|
||
'base_url' => $path,
|
||
'uri_segment' => 'page',
|
||
'total_items' => count($filter_queries),
|
||
'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->order_field('id')
|
||
->label(__('ID'));
|
||
|
||
$grid->order_field('name');
|
||
|
||
$grid->order_field('url')
|
||
->label(__('URL'));
|
||
|
||
$grid->order_callback_field('default')
|
||
->callback(
|
||
'callback::enabled_field',
|
||
$this->acl_check_edit('Filter_queries_Controller', 'filter_queries') ?
|
||
'filter_queries/set_default/' : NULL
|
||
)->class('center');
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_delete('Filter_queries_Controller', 'filter_queries'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('delete')
|
||
->url('filter_queries/delete')
|
||
->label('Delete')
|
||
->class('delete_link');
|
||
}
|
||
|
||
$grid->datasource($filter_queries);
|
||
|
||
$view = new View('main');
|
||
$view->breadcrumbs = __('Filter queries');
|
||
$view->title = $title;
|
||
$view->content = new View('show_all');
|
||
$view->content->headline = $title;
|
||
$view->content->table = $grid;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Adds new filter query
|
||
*
|
||
* @author Michal Kliment
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Filter_queries_Controller" value="filter_queries" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Filter_queries_Controller" value="filter_queries" action="edit" own="false"></axo>
|
||
<axo usage_type="unknown" section="Filter_queries_Controller" value="filter_queries" action="delete" own="false"></axo>
|
||
<axo usage_type="access" section="Filter_queries_Controller" value="filter_queries" action="view" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Filter_queries_Controller" value="filter_queries" action="edit" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Filter_queries_Controller" value="filter_queries" action="delete" own="false"></axo>
|
||
</method>
|
||
<method name="add"></method>
|
||
<method name="set_default">
|
||
<!-- set_default($filter_query_id = NULL)
|
||
{
|
||
// bad paremeter
|
||
if (!$filter_query_id || !is_numeric($filter_query_id))
|
||
Controller::warning (PARAMETER);
|
||
|
||
if (!$this->acl_check_edit('Filter_queries_Controller', 'filter_queries'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$filter_query = new Filter_query_Model($filter_query_id);
|
||
|
||
// record doesn't exis
|
||
if (!$filter_query->id)
|
||
Controller::error(RECORD);
|
||
|
||
$filter_query->transaction_start();
|
||
|
||
$is_default = $filter_query->default;
|
||
|
||
// prevent database exception
|
||
try
|
||
{
|
||
$filter_query->default = !$is_default;
|
||
$filter_query->save_throwable();
|
||
|
||
if (!$is_default)
|
||
$filter_query->repair_default();
|
||
|
||
$filter_query->transaction_commit();
|
||
|
||
if ($is_default)
|
||
status::success('Filter query has been successfully unset as default.');
|
||
else
|
||
status::success('Filter query has been successfully set as default.');
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$filter_query->transaction_rollback();
|
||
Log::add_exception($e);
|
||
if ($is_default)
|
||
status::error('Error - Cannot unset filter query as default.', $e);
|
||
else
|
||
status::error('Error - Cannot set filter query as default.', $e);
|
||
}
|
||
|
||
url::redirect($this->url('show_all'));
|
||
}
|
||
|
||
/**
|
||
* Delete query
|
||
*
|
||
* @author Michal Kliment
|
||
* @param type $filter_query_id
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Filter_queries_Controller" value="filter_queries" action="edit" own="false"></axo>
|
||
<method name="set_default"
|
||
comment-en="Enables to set default filter query for a grid (table)"
|
||
comment-cs="Umožňuje nastavit výchozí dotaz filtru gridu (tabulky)">
|
||
<axo usage_type="access" section="Filter_queries_Controller" value="filter_queries" action="edit" own="false"></axo>
|
||
</method>
|
||
<method name="delete">
|
||
<!-- delete($filter_query_id = NULL)
|
||
{
|
||
if (!$this->acl_check_delete('Filter_queries_Controller', 'filter_queries'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
// bad paremeter
|
||
if (!$filter_query_id || !is_numeric($filter_query_id))
|
||
Controller::warning (PARAMETER);
|
||
|
||
$filter_query = new Filter_query_Model($filter_query_id);
|
||
|
||
// record doesn't exis
|
||
if (!$filter_query->id)
|
||
Controller::error(RECORD);
|
||
|
||
// prevent database exception
|
||
try
|
||
{
|
||
$filter_query->delete_throwable();
|
||
|
||
status::success('Filter query has been successfully deleted.');
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
Log::add_exception($e);
|
||
status::error('Error - Cannot delete filter query.', $e);
|
||
}
|
||
|
||
url::redirect($this->url('show_all'));
|
||
}
|
||
}
|
||
-->
|
||
<axo usage_type="unknown" section="Filter_queries_Controller" value="filter_queries" action="delete" own="false"></axo>
|
||
<axo usage_type="access" section="Filter_queries_Controller" value="filter_queries" action="delete" own="false"></axo>
|
||
</method>
|
||
</object>
|
||
<object name="forgotten_password" type="controller">
|
||
<object name="forgotten_password" type="controller"
|
||
comment-en="Forgotten password - this part of system is available to an unlogged user"
|
||
comment-cs="Zapomenuté heslo - tato část sytému je dostupná nepřihlášenému uživateli">
|
||
<method name="index"></method>
|
||
</object>
|
||
<object name="ifaces" type="controller">
|
||
<object name="ifaces" type="controller"
|
||
comment-en="Ifaces - enable to manage ifaces of devices (ports, vlans, eth ifaces, bridges, etc.)"
|
||
comment-cs="Rozhraní - umožňuje spravovat rozhraní zařízení (porty, vlany, eth rozhraní, bridge, atd.)">
|
||
<method name="__construct"></method>
|
||
<method name="index"></method>
|
||
<method name="show_all">
|
||
<!-- show_all(
|
||
$limit_results = 50, $order_by = 'id',
|
||
$order_by_direction = 'asc', $page_word = null, $page = 1)
|
||
{
|
||
// access rights
|
||
if(!$this->acl_check_view('Ifaces_Controller','iface'))
|
||
Controller::error(ACCESS);
|
||
|
||
$filter_form = new Filter_form('i');
|
||
|
||
$filter_form->add('mac')
|
||
->label('MAC address')
|
||
->class('mac')
|
||
->callback('json/iface_mac');
|
||
|
||
$filter_form->add('name')
|
||
->label('Name of interface');
|
||
|
||
$filter_form->add('link_name')
|
||
->type('combo')
|
||
->callback('json/link_name');
|
||
|
||
$filter_form->add('device_name')
|
||
->type('combo')
|
||
->callback('json/device_name');
|
||
|
||
$filter_form->add('type')
|
||
->type('select')
|
||
->values(Iface_Model::get_types());
|
||
|
||
$filter_form->add('user_name')
|
||
->type('combo')
|
||
->label('Firstname of user')
|
||
->callback('json/user_name');
|
||
|
||
$filter_form->add('user_surname')
|
||
->type('combo')
|
||
->label('Surname of user')
|
||
->callback('json/user_surname');
|
||
|
||
$filter_form->add('member_name')
|
||
->type('combo')
|
||
->callback('json/member_name');
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->post('record_per_page')))
|
||
$limit_results = (int) $this->input->post('record_per_page');
|
||
|
||
// model
|
||
$iface_model = new Iface_Model();
|
||
$total_ifaces = $iface_model->count_all_ifaces($filter_form->as_sql());
|
||
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_ifaces)
|
||
$sql_offset = 0;
|
||
|
||
$ifaces = $iface_model->get_all_ifaces(
|
||
$sql_offset, (int)$limit_results, $order_by,
|
||
$order_by_direction, $filter_form->as_sql()
|
||
);
|
||
|
||
$grid = new Grid('ifaces', null,array
|
||
(
|
||
'current' => $limit_results,
|
||
'selector_increace' => 50,
|
||
'selector_min' => 50,
|
||
'selector_max_multiplier' => 10,
|
||
'base_url' => Config::get('lang').'/ifaces/show_all/'
|
||
.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
|
||
'uri_segment' => 'page',
|
||
'total_items' => $total_ifaces,
|
||
'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('Ifaces_Controller','iface'))
|
||
{
|
||
$grid->add_new_button('ifaces/add', 'Add new interface');
|
||
}
|
||
|
||
$grid->order_field('id')
|
||
->label('ID');
|
||
|
||
$grid->order_callback_field('type')
|
||
->callback('callback::iface_type_field')
|
||
->class('center');
|
||
|
||
$grid->order_field('name');
|
||
|
||
$grid->order_field('mac')
|
||
->label('MAC');
|
||
|
||
$grid->order_link_field('link_id')
|
||
->link('links/show', 'link_name')
|
||
->label('Link');
|
||
|
||
$grid->order_callback_field('device_name')
|
||
->callback('callback::device_field');
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Ifaces_Controller','iface'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('show')
|
||
->url('ifaces/show');
|
||
}
|
||
|
||
if ($this->acl_check_edit('Ifaces_Controller','iface'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('edit')
|
||
->url('ifaces/edit');
|
||
}
|
||
|
||
if ($this->acl_check_delete('Ifaces_Controller','iface'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('delete')
|
||
->url('ifaces/delete')
|
||
->class('delete_link');
|
||
}
|
||
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->text('Interfaces')
|
||
->html();
|
||
|
||
$grid->datasource($ifaces);
|
||
$headline = __('Interfaces list');
|
||
$view = new View('main');
|
||
$view->breadcrumbs = $breadcrumbs;
|
||
$view->title = $headline;
|
||
$view->content = new View('show_all');
|
||
$view->content->table = $grid;
|
||
$view->content->headline = $headline;
|
||
$view->render(TRUE);
|
||
} // end of show_all
|
||
|
||
|
||
|
||
/**
|
||
* Function shows interface details.
|
||
*
|
||
* @param integer $iface_id
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="new" own="false"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="edit" own="false"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="delete" own="false"></axo>
|
||
<axo usage_type="access" section="Ifaces_Controller" value="iface" action="view" own="false"></axo>
|
||
<axo usage_type="links" section="Ifaces_Controller" value="iface" action="new" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Ifaces_Controller" value="iface" action="view" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Ifaces_Controller" value="iface" action="edit" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Ifaces_Controller" value="iface" action="delete" own="false"></axo>
|
||
</method>
|
||
<method name="show">
|
||
<!-- show($iface_id = null)
|
||
{
|
||
// bad parameter
|
||
if (!$iface_id || !is_numeric($iface_id))
|
||
Controller::warning(PARAMETER);
|
||
|
||
$iface = new Iface_Model($iface_id);
|
||
|
||
// interface doesn't exist
|
||
if (!$iface->id)
|
||
Controller::error(RECORD);
|
||
|
||
$member_id = $iface->device->user->member_id;
|
||
|
||
// access control
|
||
if (!$this->acl_check_view('Ifaces_Controller', 'iface', $member_id))
|
||
Controller::error(ACCESS);
|
||
|
||
// ip addresses
|
||
$ip_addresses = ORM::factory('ip_address')->get_all_ip_addresses_of_iface($iface->id);
|
||
|
||
$grid_ip_addresses = new Grid('ifaces', null,array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false
|
||
));
|
||
|
||
if ($this->acl_check_new(
|
||
'Ip_addresses_Controller', 'ip_address',
|
||
$iface->device->user->member_id
|
||
))
|
||
{
|
||
$grid_ip_addresses->add_new_button(
|
||
'ip_addresses/add/'.$iface->device_id.'/'.$iface->id,
|
||
'Add new IP address'
|
||
);
|
||
}
|
||
|
||
$grid_ip_addresses->field('id')
|
||
->label('ID')
|
||
->class('center');
|
||
|
||
$grid_ip_addresses->field('ip_address')
|
||
->label('IP address');
|
||
|
||
if ($this->acl_check_view('Subnets_Controller', 'subnet'))
|
||
{
|
||
$grid_ip_addresses->link_field('subnet_id')
|
||
->link('subnets/show', 'subnet_name')
|
||
->label('Subnet');
|
||
}
|
||
else
|
||
{
|
||
$grid_ip_addresses->field('subnet_name')
|
||
->label('Subnet');
|
||
}
|
||
|
||
$actions = $grid_ip_addresses->grouped_action_field();
|
||
|
||
if ($this->acl_check_view(
|
||
'Ip_addresses_Controller', 'ip_address',
|
||
$iface->device->user->member_id
|
||
))
|
||
{
|
||
$actions->add_action()
|
||
->icon_action('show')
|
||
->url('devices/show_ip_address');
|
||
}
|
||
|
||
if ($this->acl_check_edit(
|
||
'Ip_addresses_Controller', 'ip_address',
|
||
$iface->device->user->member_id
|
||
))
|
||
{
|
||
$actions->add_action()
|
||
->icon_action('edit')
|
||
->url('ip_addresses/edit');
|
||
}
|
||
|
||
if ($this->acl_check_delete(
|
||
'Ip_addresses_Controller', 'ip_address',
|
||
$iface->device->user->member_id
|
||
))
|
||
{
|
||
$actions->add_action()
|
||
->icon_action('delete')
|
||
->url('ip_addresses/delete')
|
||
->class('delete_link');
|
||
}
|
||
|
||
$grid_ip_addresses->datasource($ip_addresses);
|
||
|
||
if ($iface->name != '')
|
||
{
|
||
$name = $iface->name;
|
||
if ($iface->mac != '')
|
||
$name .= " ($iface->mac)";
|
||
}
|
||
else
|
||
{
|
||
$name = $iface->mac;
|
||
}
|
||
|
||
if (url::slice(url_lang::uri(Path::instance()->previous()), 0, 1) != 'ifaces')
|
||
{
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link(
|
||
'members/show_all', 'Members',
|
||
$this->acl_check_view('Members_Controller','members')
|
||
)
|
||
->link(
|
||
'members/show/'.$iface->device->user->member_id,
|
||
'ID '.$iface->device->user->member->id.' - '.$iface->device->user->member->name,
|
||
$this->acl_check_view(
|
||
'Members_Controller', 'members',
|
||
$iface->device->user->member_id
|
||
)
|
||
)
|
||
->link(
|
||
'users/show_by_member/'.$iface->device->user->member_id,
|
||
'Users', $this->acl_check_view(
|
||
'Users_Controller', 'users', $iface->device->user->member_id
|
||
)
|
||
)
|
||
->link(
|
||
'users/show/'.$iface->device->user_id,
|
||
$iface->device->user->get_full_name(), $this->acl_check_view(
|
||
'Users_Controller', 'users',
|
||
$iface->device->user->member_id
|
||
)
|
||
)
|
||
->link(
|
||
'devices/show_by_user/'.$iface->device->user_id,
|
||
'Devices', $this->acl_check_view(
|
||
'Devices_Controller',
|
||
'devices',
|
||
$iface->device->user->member_id
|
||
)
|
||
)
|
||
->link(
|
||
'devices/show/'.$iface->device_id,
|
||
$iface->device->name, $this->acl_check_view(
|
||
'Devices_Controller', 'devices',
|
||
$iface->device->user->member_id
|
||
)
|
||
)->text($name)
|
||
->html();
|
||
}
|
||
else
|
||
{
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link(
|
||
'ifaces/show_all', 'Interfaces',
|
||
$this->acl_check_view('Ifaces_Controller', 'iface')
|
||
)
|
||
->text($name)
|
||
->html();
|
||
}
|
||
|
||
$headline = __('Interface detail').' - '.$iface->name;
|
||
$view = new View('main');
|
||
$view->breadcrumbs = $breadcrumbs;
|
||
$view->action_logs = action_logs::object_last_modif($iface, $iface_id);
|
||
$view->title = $headline;
|
||
$view->content = new View('ifaces/show');
|
||
|
||
$detail = '';
|
||
$child_ifaces = '';
|
||
$port_vlan = '';
|
||
|
||
switch ($iface->type)
|
||
{
|
||
case Iface_Model::TYPE_WIRELESS:
|
||
$detail = new View('ifaces/detail');
|
||
$detail->ip_addresses = $grid_ip_addresses;
|
||
|
||
if ($iface->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
|
||
{
|
||
$iface_model = new Iface_Model();
|
||
$children = $iface_model->get_virtual_ap_ifaces_of_parent($iface->id);
|
||
|
||
$data = $children->as_array();
|
||
|
||
if ($data)
|
||
{
|
||
$child_ifaces = new Grid('ifaces', null,array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false
|
||
));
|
||
$child_ifaces->add_new_button(
|
||
'ifaces/add/'.$iface->device_id.'/'.Iface_Model::TYPE_VIRTUAL_AP,
|
||
'Add new Virtual AP'
|
||
);
|
||
|
||
$child_ifaces->field('id')
|
||
->label('ID')
|
||
->class('center');
|
||
|
||
$child_ifaces->field('name')
|
||
->link('ifaces/show')
|
||
->label('Name');
|
||
|
||
$actions = $child_ifaces->grouped_action_field();
|
||
$actions->add_action()
|
||
->icon_action('show')
|
||
->url('ifaces/show');
|
||
$actions->add_action()
|
||
->icon_action('edit')
|
||
->url('ifaces/edit');
|
||
$actions->add_action()
|
||
->icon_action('delete')
|
||
->url('ifaces/detele')
|
||
->class('delete_link');
|
||
|
||
$child_ifaces->datasource($data);
|
||
}
|
||
}
|
||
break;
|
||
case Iface_Model::TYPE_ETHERNET:
|
||
$detail = new View('ifaces/detail');
|
||
$detail->ip_addresses = $grid_ip_addresses;
|
||
break;
|
||
case Iface_Model::TYPE_BRIDGE:
|
||
$iv = new Ifaces_vlan_Model();
|
||
$ifaces = $iv->get_all_bridged_ifaces_of_iface($iface_id);
|
||
|
||
$member_id = $iface->device->user->member_id;
|
||
|
||
// grid
|
||
$grid = new Grid('devices', null, array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false,
|
||
'total_items' => count($ifaces)
|
||
));
|
||
|
||
/**
|
||
* @todo Add method to add interface to bridge
|
||
*/
|
||
|
||
/*if ($this->acl_check_new('Ifaces_Controller', 'iface', $member_id))
|
||
{
|
||
$grid->add_new_button(
|
||
'ifaces/add/' . $iface->device->id, 'Add new interface'
|
||
);
|
||
}*/
|
||
|
||
$grid->callback_field('type')
|
||
->callback('callback::iface_type_field')
|
||
->class('center');
|
||
|
||
$grid->field('name');
|
||
|
||
$grid->callback_field('mac')
|
||
->callback('callback::not_empty')
|
||
->label('MAC')
|
||
->class('center');
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Ifaces_Controller', 'iface', $member_id))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('show')
|
||
->url('devices/show_iface')
|
||
->class('popup_link');
|
||
}
|
||
|
||
if ($this->acl_check_delete('Ifaces_Controller', 'iface', $member_id))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('delete')
|
||
->url('ifaces/remove_from_bridge/'.$iface->id)
|
||
->class('delete_link')
|
||
->label('Remove interface from bridge');
|
||
}
|
||
|
||
$grid->datasource($ifaces);
|
||
$detail = $grid;
|
||
break;
|
||
case Iface_Model::TYPE_PORT:
|
||
$vl = new Vlan_Model();
|
||
$vlans = $vl->get_all_vlans_of_iface($iface_id);
|
||
$port_vlan = $vl->get_default_vlan_of_interface($iface_id);
|
||
|
||
// grid
|
||
$grid = new Grid('devices', null, array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false,
|
||
'total_items' => count($vlans)
|
||
));
|
||
|
||
$grid->field('name')
|
||
->label('VLAN name');
|
||
|
||
$grid->field('tag_802_1q')
|
||
->class('center');
|
||
|
||
$grid->callback_field('tagged')
|
||
->callback('callback::boolean')
|
||
->label('Tagged VLAN')
|
||
->class('center');
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
$actions->add_action('vlan_id')
|
||
->icon_action('show')
|
||
->url('vlans/show')
|
||
->class('popup_link');
|
||
|
||
$actions->add_conditional_action('vlan_id')
|
||
->icon_action('delete')
|
||
->condition('is_not_default_vlan')
|
||
->url('vlans/remove_from_port/'.$iface->id)
|
||
->class('delete_link');
|
||
|
||
|
||
$grid->datasource($vlans);
|
||
$detail = $grid;
|
||
break;
|
||
case Iface_Model::TYPE_INTERNAL:
|
||
$detail = new View('ifaces/detail');
|
||
$detail->ip_addresses = $grid_ip_addresses;
|
||
break;
|
||
};
|
||
|
||
$view->content->iface = $iface;
|
||
$view->content->detail = $detail;
|
||
$view->content->headline = $headline;
|
||
$view->content->port_vlan = $port_vlan;
|
||
$view->content->child_ifaces = $child_ifaces;
|
||
$view->render(TRUE);
|
||
} // end of show
|
||
|
||
/**
|
||
* Function adds new interface.
|
||
*
|
||
* @param integer $device_id Device ID
|
||
* @param integer $type Iface type
|
||
* @param boolean $add_button If opened by add button
|
||
* @param integer $connect_type Connect to iface type - only if add_button
|
||
*/
|
||
public -->
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Ip_addresses_Controller" value="ip_address" action="new" own="true"></axo>
|
||
<axo usage_type="unknown" section="Subnets_Controller" value="subnet" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Ip_addresses_Controller" value="ip_address" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Ip_addresses_Controller" value="ip_address" action="edit" own="true"></axo>
|
||
<axo usage_type="unknown" section="Ip_addresses_Controller" value="ip_address" action="delete" own="true"></axo>
|
||
<axo usage_type="unknown" section="Members_Controller" value="members" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Members_Controller" value="members" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Users_Controller" value="users" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Users_Controller" value="users" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Devices_Controller" value="devices" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Devices_Controller" value="devices" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="view" own="false"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="new" own="true"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="view" own="true"></axo>
|
||
<axo usage_type="unknown" section="Ifaces_Controller" value="iface" action="delete" own="true"></axo>
|
||
<axo usage_type="access" section="Ifaces_Controller" value="iface" action="view" own="true"></axo>
|
||
<axo usage_type="links" section="Ip_addresses_Controller" value="ip_address" action="new" own="true"></axo>
|
||
<axo usage_type="links" section="Subnets_Controller" value="subnet" action="view" own="false"></axo>
|
||
<axo usage_type="grid-action" section="Ip_addresses_Controller" value="ip_address" action="view" own="true"></axo>
|
||
<axo usage_type="grid-action" section="Ip_addresses_Controller" value="ip_address" action="edit" own="true"></axo>
|
||
<axo usage_type="grid-action" section="Ip_addresses_Controller" value="ip_address" action="delete" own="true"></axo>
|
||
<axo usage_type="grid-action" section="Members_Controller" value="members" action="view" own="false"></axo>
|
||
<axo usage_type="breadcrumbs" section="Members_Controller" value="members" action="view" own="true"></axo>
|
||
<axo usage_type="breadcrumbs" section="Users_Controller" value="users" action="view" own="true"></axo>
|
||
<axo usage_type="breadcrumbs" section="Users_Controller" value="users" action="view" own="true"></axo>
|
||
<axo usage_type="breadcrumbs" section="Devices_Controller" value="devices" action="view" own="true"></axo>
|
||
<axo usage_type="breadcrumbs" section="Devices_Controller" value="devices" action="view" own="true"></axo>
|
||
<axo usage_type="breadcrumbs" section="Ifaces_Controller" value="iface" action="view" own="false"></axo>
|
||
<axo usage_type="links" section="Ifaces_Controller" value="iface" action="new" own="true"></axo>
|
||
<axo usage_type="grid-action" section="Ifaces_Controller" value="iface" action="view" own="true"></axo>
|
||
<axo usage_type="grid-action" section="Ifaces_Controller" value="iface" action="delete" own="true"></axo>
|
||
</method>
|
||
<method name="add">
|
||
<!-- add($device_id = NULL, $type = NULL,
|
||
$add_button = FALSE, $connect_type = NULL)
|
||
{
|
||
if (!$this->acl_check_new('Ifaces_Controller', 'iface'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
// device is set
|
||
if (is_numeric($device_id))
|
||
{
|
||
$device = new Device_Model($device_id);
|
||
|
||
if (!$device->id)
|
||
{
|
||
Controller::error(RECORD);
|
||
}
|
||
|
||
$breadcrumbs = breadcrumbs::add()->link(
|
||
'members/show_all', 'Members',
|
||
$this->acl_check_view('Members_Controller', 'members')
|
||
)->link(
|
||
'members/show/'.$device->user->member_id,
|
||
'ID '.$device->user->member->id.' - '.$device->user->member->name,
|
||
$this->acl_check_view(
|
||
'Members_Controller', 'members', $device->user->member_id
|
||
)
|
||
)->link(
|
||
'users/show_by_member/'.$device->user->member_id, 'Users',
|
||
$this->acl_check_view(
|
||
'Users_Controller', 'users', $device->user->member_id
|
||
)
|
||
)->link(
|
||
'users/show/'.$device->user_id, $device->user->get_full_name(),
|
||
$this->acl_check_view(
|
||
'Users_Controller', 'users', $device->user->member_id
|
||
)
|
||
)->link(
|
||
'devices/show_by_user/'.$device->user_id, 'Devices',
|
||
$this->acl_check_view(
|
||
'Devices_Controller', 'devices', $device->user->member_id
|
||
)
|
||
)->link(
|
||
'devices/show/'.$device_id, $device->name, $this->acl_check_view(
|
||
'Devices_Controller', 'devices', $device->user->member_id
|
||
)
|
||
)->text('Add new interface')
|
||
->html();
|
||
}
|
||
else
|
||
{
|
||
$breadcrumbs = breadcrumbs::add()->link(
|
||
'ifaces/show_all', 'Interfaces',
|
||
$this->acl_check_view('Ifaces_Controller', 'iface')
|
||
)->text('Add new interface')
|
||
->html();
|
||
}
|
||
|
||
// only one connected to => skip selecting of type
|
||
if (is_numeric($device_id) && $add_button && is_numeric($connect_type))
|
||
{
|
||
$conn_types = Iface_Model::get_can_connect_to($connect_type);
|
||
|
||
if (count($conn_types) == 1)
|
||
{
|
||
$type = $conn_types[0];
|
||
$connect_type = null;
|
||
}
|
||
}
|
||
|
||
if (is_numeric($device_id) && is_numeric($type) && empty($connect_type))
|
||
{
|
||
$im = new Iface_Model();
|
||
|
||
// iface type doesn't exist
|
||
if (!$im->get_type($type))
|
||
{
|
||
Controller::error(RECORD);
|
||
}
|
||
|
||
$this->device_id = $device_id;
|
||
$this->iface_type = $type;
|
||
|
||
$filter_form = Devices_Controller::device_filter_form($device->user_id);
|
||
|
||
$form = new Forge('ifaces/add/' . $device_id . '/' . $type);
|
||
|
||
$base_form = $form->group('Basic data');
|
||
|
||
$form->hidden('itype')
|
||
->value($type);
|
||
|
||
$base_form->input('name')
|
||
->label('Interface name')
|
||
->rules('length[3,250]')
|
||
->style('width:620px')
|
||
->value(Iface_Model::get_default_name($type) . ' ' . $device->name);
|
||
|
||
// print mac address field only if it can have mac address
|
||
if (Iface_Model::type_has_mac_address($type))
|
||
{
|
||
$base_form->input('mac')
|
||
->label('MAC')
|
||
->rules('valid_mac_address')
|
||
->style('width:620px');
|
||
}
|
||
|
||
$base_form->textarea('comment')
|
||
->rules('length[0,254]')
|
||
->cols('20')
|
||
->rows('5')
|
||
->style('width: 620px');
|
||
|
||
// print parent iface field only if type is VLAN
|
||
if ($type == Iface_Model::TYPE_VLAN)
|
||
{
|
||
$parent_ifaces = array();
|
||
|
||
foreach ($device->ifaces as $iface)
|
||
{
|
||
// limit options only if type is given
|
||
if (in_array($iface->type, Iface_Model::get_can_be_child_of($type)))
|
||
{
|
||
$parent_ifaces[$iface->id] = $iface->name . ' - ' . $iface->device->name;
|
||
}
|
||
}
|
||
|
||
$parent_ifaces = array
|
||
(
|
||
NULL => '- '.__('Select interface').' -'
|
||
) + $parent_ifaces;
|
||
|
||
$vlan_ifaces = array
|
||
(
|
||
NULL => '- '.__('Select VLAN').' -'
|
||
) + ORM::factory('vlan')->select_list();
|
||
|
||
$vlan_form = $form->group('VLAN setting');
|
||
|
||
$vlan_form->dropdown('vlan_id')
|
||
->label('VLAN')
|
||
->options($vlan_ifaces)
|
||
->rules('required')
|
||
->add_button('vlans')
|
||
->style('width:200px');
|
||
|
||
$vlan_form->dropdown('parent_iface_id')
|
||
->label('Parent interface')
|
||
->options($parent_ifaces)
|
||
->rules('required')
|
||
->style('width:200px');
|
||
}
|
||
|
||
// print children ifaces field only if type is bridge
|
||
if ($type == Iface_Model::TYPE_BRIDGE)
|
||
{
|
||
$child_ifaces = array();
|
||
|
||
foreach ($device->ifaces as $iface)
|
||
{
|
||
// limit options only if type is given
|
||
if (in_array($type, Iface_Model::get_can_be_child_of($iface->type)))
|
||
{
|
||
$mac = ($iface->mac) ? $iface->mac . ' - ' : '';
|
||
$child_ifaces[$iface->id] = $mac . $iface->name;
|
||
}
|
||
}
|
||
|
||
$bridge_form = $form->group('Bridge settings');
|
||
|
||
$bridge_form->dropdown('children_interfaces[]')
|
||
->multiple('multiple')
|
||
->options($child_ifaces)
|
||
->size(15)
|
||
->label('Children interfaces');
|
||
}
|
||
|
||
// print port fields only if type is port
|
||
if ($type == Iface_Model::TYPE_PORT)
|
||
{
|
||
$modes = array
|
||
(
|
||
NULL => '- '.__('Select mode').' -'
|
||
) + Iface_Model::get_port_modes();
|
||
|
||
$vlan_model = new Vlan_Model();
|
||
$arr_vlans = $vlan_model->select_list();
|
||
$default_vlan = $vlan_model->get_default_vlan();
|
||
|
||
$default_vlans = array
|
||
(
|
||
NULL => '- ' . __('Select VLAN') . ' -'
|
||
) + $arr_vlans;
|
||
|
||
$port_form = $form->group('Port setting');
|
||
|
||
$port_form->input('number')
|
||
->value($device->get_next_port_number())
|
||
->class('increase_decrease_buttons')
|
||
->callback(array($this, 'valid_port_nr'));
|
||
|
||
if (!$add_button)
|
||
{
|
||
$vlan_port_form = $form->group('Port VLAN setting')->visible(FALSE);
|
||
|
||
$vlan_port_form->dropdown('port_mode')
|
||
->options($modes)
|
||
->selected(Iface_Model::PORT_MODE_ACCESS)
|
||
->rules('required')
|
||
->style('width:200px');
|
||
|
||
$vlan_port_form->dropdown('port_vlan_id')
|
||
->options($default_vlans)
|
||
->selected($default_vlan->id)
|
||
->rules('required')
|
||
->label('Port VLAN')
|
||
->help('port_vlan')
|
||
->callback(array($this, 'valid_port_vlan'))
|
||
->style('width:200px')
|
||
->add_button('vlans');
|
||
|
||
$vlan_port_form->dropdown('tagged_vlan_id[]')
|
||
->label('Tagged VLANs')
|
||
->options($arr_vlans)
|
||
->multiple('multiple')
|
||
->size(10)
|
||
->add_button('vlans');
|
||
|
||
$vlan_port_form->dropdown('untagged_vlan_id[]')
|
||
->label('Untagged VLANs')
|
||
->options($arr_vlans)
|
||
->selected($default_vlan->id)
|
||
->callback(array($this, 'valid_vlans'))
|
||
->multiple('multiple')
|
||
->size(10)
|
||
->add_button('vlans');
|
||
}
|
||
else
|
||
{
|
||
$form->hidden('port_mode')
|
||
->value(Iface_Model::PORT_MODE_ACCESS);
|
||
|
||
$form->hidden('port_vlan_id')
|
||
->value($default_vlan->id);
|
||
|
||
$form->hidden('tagged_vlan_id[]');
|
||
|
||
$form->hidden('untagged_vlan_id')
|
||
->value($default_vlan->id);
|
Také k dispozici: Unified diff
Upravy:
- refs #563: dokumentace k AXO (controllery F az J)