Revize 2133
Přidáno uživatelem David Raška před více než 11 roky(ů)
freenetis/branches/1.1/application/controllers/device_active_links.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 device active links actions.
|
||
*
|
||
* @package Controller
|
||
*/
|
||
class Device_active_links_Controller extends Controller
|
||
{
|
||
/**
|
||
* Constructor, only test if networks is enabled
|
||
*/
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
|
||
// access control
|
||
if (!Settings::get('networks_enabled'))
|
||
Controller::error (ACCESS);
|
||
}
|
||
|
||
/**
|
||
* Index redirects to show all
|
||
*/
|
||
public function index()
|
||
{
|
||
url::redirect('device_active_links/show_all');
|
||
}
|
||
|
||
/**
|
||
* Function shows all device active_links.
|
||
*
|
||
* @param integer $limit_results devices per page
|
||
* @param string $order_by sorting column
|
||
* @param string $order_by_direction sorting direction
|
||
*/
|
||
public function show_all($limit_results = 50, $order_by = 'device_id',
|
||
$order_by_direction = 'ASC', $page_word = null, $page = 1)
|
||
{
|
||
// access control
|
||
if (!$this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
Controller::error(ACCESS);
|
||
|
||
$filter_form = new Filter_form('dal');
|
||
|
||
$filter_form->add('url_pattern')
|
||
->label('URL pattern');
|
||
|
||
$filter_form->add('name');
|
||
|
||
$filter_form->add('title');
|
||
|
||
$filter_form->add('show_in_user_grid')
|
||
->type('select')
|
||
->values(arr::bool());
|
||
|
||
$filter_form->add('show_in_grid')
|
||
->type('select')
|
||
->values(arr::bool());
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->post('record_per_page')))
|
||
$limit_results = (int) $this->input->post('record_per_page');
|
||
|
||
$device_active_link_model = new Device_active_link_Model;
|
||
$total_active_links = $device_active_link_model->count_all_active_links($filter_form->as_sql());
|
||
|
||
// limit check
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_active_links)
|
||
$sql_offset = 0;
|
||
|
||
// query
|
||
$active_links = $device_active_link_model->get_all_active_links(array
|
||
(
|
||
'offset' => $sql_offset,
|
||
'limit' => (int) $limit_results,
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'filter_sql' => $filter_form->as_sql()
|
||
));
|
||
|
||
// headline
|
||
$headline = __('Device active links');
|
||
|
||
// grid of devices
|
||
$grid = new Grid('device_active_links', null, array
|
||
(
|
||
'current' => $limit_results,
|
||
'selector_increace' => 50,
|
||
'selector_min' => 50,
|
||
'selector_max_multiplier' => 20,
|
||
'base_url' => Config::get('lang'). '/device_active_links/show_all/'
|
||
. $limit_results.'/'.$order_by.'/'.$order_by_direction,
|
||
'uri_segment' => 'page',
|
||
'total_items' => $total_active_links,
|
||
'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('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
$grid->add_new_button('device_active_links/add', 'Add new device active link');
|
||
}
|
||
|
||
$grid->order_field('id')
|
||
->label('ID')
|
||
->class('center');
|
||
|
||
$grid->order_field('url_pattern')
|
||
->label('URL pattern');
|
||
|
||
$grid->order_field('name')
|
||
->label('Name');
|
||
|
||
$grid->order_field('title')
|
||
->label('title');
|
||
|
||
$grid->order_callback_field('devices_count')
|
||
->class('center');
|
||
|
||
$grid->order_callback_field('show_in_user_grid')
|
||
->label('Show in user grid')
|
||
->callback('callback::enabled_field', '')
|
||
->class('center');
|
||
|
||
$grid->order_callback_field('show_in_grid')
|
||
->label('Show in grid')
|
||
->callback('callback::enabled_field', '')
|
||
->class('center');
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('show')
|
||
->url('device_active_links/show');
|
||
}
|
||
|
||
if ($this->acl_check_edit('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('edit')
|
||
->url('device_active_links/edit');
|
||
}
|
||
|
||
if ($this->acl_check_delete('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('delete')
|
||
->url('device_active_links/delete')
|
||
->class('delete_link');
|
||
}
|
||
|
||
$grid->datasource($active_links);
|
||
|
||
// view
|
||
$view = new View('main');
|
||
$view->title = $headline;
|
||
$view->breadcrumbs = $headline;
|
||
$view->content = new View('show_all');
|
||
$view->content->headline = $headline;
|
||
$view->content->table = $grid;
|
||
$view->render(TRUE);
|
||
} // end of show_all function
|
||
|
||
/**
|
||
* Function shows device action link.
|
||
*
|
||
* @param integer $device_id
|
||
*/
|
||
public function show($active_link_id = null)
|
||
{
|
||
if (!$this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
if (!isset($active_link_id))
|
||
{
|
||
Controller::warning(PARAMETER);
|
||
}
|
||
|
||
$active_link = new Device_active_link_Model($active_link_id);
|
||
|
||
if ($active_link->id == 0)
|
||
{
|
||
Controller::error(RECORD);
|
||
}
|
||
|
||
$devices = $active_link->get_active_link_devices();
|
||
$device_templates = $active_link->get_active_link_devices(NULL,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
$devices_grid = new Grid('devices', null, array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false,
|
||
'total_items' => $devices->count()
|
||
));
|
||
|
||
$devices_grid->Field('id')
|
||
->label('ID');
|
||
|
||
$devices_grid->Field('name');
|
||
|
||
if ($this->acl_check_view('Devices_Controller', 'devices'))
|
||
{
|
||
$actions = $devices_grid->grouped_action_field();
|
||
|
||
$actions->add_conditional_action('id')
|
||
->icon_action('show')
|
||
->url('devices/show');
|
||
}
|
||
|
||
$devices_grid->datasource($devices);
|
||
|
||
$device_templates_grid = new Grid('device_templaes', null, array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false,
|
||
'total_items' => $device_templates->count()
|
||
));
|
||
|
||
$device_templates_grid->Field('id')
|
||
->label('ID');
|
||
|
||
$device_templates_grid->Field('name');
|
||
|
||
if ($this->acl_check_view('Device_templates_Controller', 'device_template'))
|
||
{
|
||
$actions = $device_templates_grid->grouped_action_field();
|
||
|
||
$actions->add_conditional_action('id')
|
||
->icon_action('show')
|
||
->url('device_templates/show');
|
||
}
|
||
|
||
$device_templates_grid->datasource($device_templates);
|
||
|
||
// breadcrumbs navigation
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link('device_active_links/show_all', 'Device active links',
|
||
$this->acl_check_view('Device_active_links_Controller','active_links'))
|
||
->disable_translation()
|
||
->text('ID ' . $active_link->id . ' - ' .
|
||
(!$active_link->name ? $active_link->title : $active_link->name));
|
||
|
||
// view
|
||
$view = new View('main');
|
||
$view->title = __('Device active link').' '.
|
||
(!$active_link->name ? $active_link->title : $active_link->name);
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('device_active_links/show');
|
||
$view->content->active_link = $active_link;
|
||
$view->content->devices_grid = $devices_grid;
|
||
$view->content->device_templates_grid = $device_templates_grid;
|
||
$view->content->headline = __('Device active link').' '.
|
||
(!$active_link->name ? $active_link->title : $active_link->name);
|
||
$view->render(TRUE);
|
||
} // end of show
|
||
|
||
/**
|
||
* Adds new device active link
|
||
*/
|
||
public function add()
|
||
{
|
||
if (!$this->acl_check_new('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$device_model = new Device_Model();
|
||
$devices = $device_model->select_list_device();
|
||
|
||
$device_template_model = new Device_template_Model();
|
||
$all_device_templates = $device_template_model->get_all_templates();
|
||
|
||
$device_templates = array();
|
||
foreach ($all_device_templates AS $dt)
|
||
{
|
||
$device_templates[$dt->id] = $dt->name;
|
||
}
|
||
|
||
// forge form
|
||
$form = new Forge();
|
||
|
||
$form->input('url_pattern')
|
||
->label('URL pattern')
|
||
->rules('required');
|
||
|
||
$form->input('name');
|
||
|
||
$form->input('title')
|
||
->rules('required');
|
||
|
||
$form->dropdown('show_in_user_grid')
|
||
->options(arr::bool());
|
||
|
||
$form->dropdown('show_in_grid')
|
||
->options(arr::bool());
|
||
|
||
$form->dropdown('devices[]')
|
||
->label('Devices')
|
||
->options($devices)
|
||
->multiple('multiple')
|
||
->size(20);
|
||
|
||
$form->dropdown('device_templates[]')
|
||
->label('Device templates')
|
||
->options($device_templates)
|
||
->multiple('multiple')
|
||
->size(20);
|
||
|
||
$form->submit('Add');
|
||
|
||
// validates form and saves data
|
||
if ($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
if (!$form_data['devices'])
|
||
{
|
||
$form_data['devices'] = array();
|
||
}
|
||
|
||
$dal = new Device_active_link_Model();
|
||
|
||
try
|
||
{
|
||
$dal->transaction_start();
|
||
|
||
$dal->url_pattern = $form_data['url_pattern'];
|
||
$dal->name = $form_data['name'];
|
||
$dal->title = $form_data['title'];
|
||
$dal->show_in_user_grid = $form_data['show_in_user_grid'];
|
||
$dal->show_in_grid = $form_data['show_in_grid'];
|
||
|
||
$dal->save_throwable();
|
||
|
||
// map devices
|
||
$dal->map_devices_to_active_link($form_data['devices'], $dal->id);
|
||
|
||
// map templates
|
||
$dal->map_devices_to_active_link(
|
||
$form_data['device_templates'],
|
||
$dal->id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
$dal->transaction_commit();
|
||
|
||
$this->redirect('device_active_links/show_all');
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$dal->transaction_rollback();
|
||
|
||
Log::add_exception($e);
|
||
status::error('Device active link has not been successfully saved.', $e);
|
||
}
|
||
}
|
||
|
||
$headline = __('Add new device active link');
|
||
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link('device_active_links/show_all', 'Device active links',
|
||
$this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
->disable_translation()
|
||
->text($headline);
|
||
|
||
$view = new View('main');
|
||
$view->title = $headline;
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('device_active_links/add');
|
||
$view->content->form = $form->html();
|
||
$view->content->headline = $headline;
|
||
$view->render(TRUE);
|
||
} // end of function add
|
||
|
||
/**
|
||
* Function edits device.
|
||
*
|
||
* @param integer $device_active_link_id
|
||
*/
|
||
public function edit($device_active_link_id = null)
|
||
{
|
||
if (!$this->acl_check_edit('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
// Get devices
|
||
$device_model = new Device_Model();
|
||
$devices = $device_model->select_list_device();
|
||
|
||
// Get device templates
|
||
$device_template_model = new Device_template_Model();
|
||
$all_device_templates = $device_template_model->get_all_templates();
|
||
|
||
$device_templates = array();
|
||
foreach ($all_device_templates AS $dt)
|
||
{
|
||
$device_templates[$dt->id] = $dt->name;
|
||
}
|
||
|
||
// Get selected devices
|
||
$active_link = new Device_active_link_Model($device_active_link_id);
|
||
|
||
$selected_devices = array();
|
||
|
||
foreach ($active_link->get_active_link_devices() AS $device)
|
||
{
|
||
$selected_devices[] = $device->id;
|
||
}
|
||
// get selected device templates
|
||
$selected_device_templates = array();
|
||
foreach ($active_link->get_active_link_devices(NULL, Device_active_link_Model::TYPE_TEMPLATE) AS $dt)
|
||
{
|
||
$selected_device_templates[] = $dt->id;
|
||
}
|
||
|
||
// forge form
|
||
$form = new Forge();
|
||
|
||
$form->input('url_pattern')
|
||
->label('URL pattern')
|
||
->rules('required')
|
||
->value($active_link->url_pattern);
|
||
|
||
$form->input('name')
|
||
->value($active_link->name);
|
||
|
||
$form->input('title')
|
||
->rules('required')
|
||
->value($active_link->title);
|
||
|
||
$form->dropdown('show_in_user_grid')
|
||
->options(arr::bool())
|
||
->value($active_link->show_in_user_grid);
|
||
|
||
$form->dropdown('show_in_grid')
|
||
->options(arr::bool())
|
||
->value($active_link->show_in_grid);
|
||
|
||
$form->dropdown('devices[]')
|
||
->label('Devices')
|
||
->options($devices)
|
||
->selected($selected_devices)
|
||
->multiple('multiple')
|
||
->size(20);
|
||
|
||
$form->dropdown('device_templates[]')
|
||
->label('Device templates')
|
||
->options($device_templates)
|
||
->selected($selected_device_templates)
|
||
->multiple('multiple')
|
||
->size(20);
|
||
|
||
$form->submit('Edit');
|
||
|
||
// validates form and saves data
|
||
if ($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
if (!$form_data['devices'])
|
||
{
|
||
$form_data['devices'] = array();
|
||
}
|
||
|
||
try
|
||
{
|
||
$active_link->transaction_start();
|
||
|
||
$active_link->url_pattern = $form_data['url_pattern'];
|
||
$active_link->name = $form_data['name'];
|
||
$active_link->title = $form_data['title'];
|
||
$active_link->show_in_user_grid = $form_data['show_in_user_grid'];
|
||
$active_link->show_in_grid = $form_data['show_in_grid'];
|
||
|
||
$active_link->save_throwable();
|
||
|
||
$active_link->unmap_devices_from_active_link($active_link->id);
|
||
$active_link->map_devices_to_active_link($form_data['devices'], $active_link->id);
|
||
|
||
$active_link->unmap_devices_from_active_link($active_link->id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
$active_link->map_devices_to_active_link($form_data['device_templates'], $active_link->id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
$active_link->transaction_commit();
|
||
|
||
$this->redirect(Path::instance()->previous());
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$active_link->transaction_rollback();
|
||
|
||
Log::add_exception($e);
|
||
status::error('Device active link has not been successfully saved.', $e);
|
||
}
|
||
}
|
||
|
||
$headline = __('Edit device active link');
|
||
|
||
$breadcrumbs = breadcrumbs::add()
|
||
->link('device_active_links/show_all', 'Device active links',
|
||
$this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
->link('device_active_links/show/' . $active_link->id,
|
||
'ID ' . $active_link->id . ' - ' .
|
||
(!$active_link->name ? $active_link->title : $active_link->name),
|
||
$this->acl_check_view('Device_active_links_Controller','active_links'))
|
||
->disable_translation()
|
||
->text($headline);
|
||
|
||
$view = new View('main');
|
||
$view->title = __('Edit device active link').' '.
|
||
(!$active_link->name ? $active_link->title : $active_link->name);
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->content = new View('device_active_links/add');
|
||
$view->content->form = $form->html();
|
||
$view->content->headline = __('Edit device active link').' '.
|
||
(!$active_link->name ? $active_link->title : $active_link->name);
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Deletes device action link
|
||
*
|
||
* @author David Raška
|
||
* @param integer $device_active_link_id
|
||
*/
|
||
public function delete($device_active_link_id = null)
|
||
{
|
||
if (!isset($device_active_link_id))
|
||
{
|
||
Controller::warning(PARAMETER);
|
||
}
|
||
|
||
$active_link = new Device_active_link_Model($device_active_link_id);
|
||
|
||
if (!$active_link->id)
|
||
{
|
||
Controller::error(RECORD);
|
||
}
|
||
|
||
if (!$this->acl_check_delete('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$linkback = Path::instance()->previous();
|
||
|
||
if (url::slice(url_lang::uri($linkback), 1, 1) == 'show')
|
||
{
|
||
$linkback = 'device_active_links/show_all';
|
||
}
|
||
|
||
// delete
|
||
try
|
||
{
|
||
$active_link->delete_throwable();
|
||
|
||
status::success('Device active link has been successfully deleted.');
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
Log::add_exception($e);
|
||
status::error(__($e->getMessage()), $e);
|
||
}
|
||
|
||
$this->redirect($linkback);
|
||
}
|
||
}
|
freenetis/branches/1.1/application/controllers/device_templates.php | ||
---|---|---|
Controller::error(RECORD);
|
||
}
|
||
|
||
$device_active_link = new Device_active_link_Model();
|
||
$active_links = $device_active_link->get_device_active_links(
|
||
$device_template_id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
$active_links_grid = new Grid('devices', null, array
|
||
(
|
||
'use_paginator' => false,
|
||
'use_selector' => false,
|
||
'total_items' => $active_links->count()
|
||
));
|
||
|
||
$active_links_grid->Field('id')
|
||
->label('ID');
|
||
|
||
$active_links_grid->Field('url_pattern')
|
||
->label('URL pattern');
|
||
|
||
$active_links_grid->Field('name');
|
||
|
||
$active_links_grid->Field('title');
|
||
|
||
if ($this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
$actions = $active_links_grid->grouped_action_field();
|
||
|
||
$actions->add_action('id')
|
||
->icon_action('show')
|
||
->url('device_active_links/show');
|
||
}
|
||
|
||
$active_links_grid->datasource($active_links);
|
||
|
||
$headline = $device_templates_model->name . ' (' . $device_template_id . ')';
|
||
|
||
// bread crumbs
|
||
... | ... | |
$view->content->device_template = $device_templates_model;
|
||
$view->content->iface_model = new Iface_Model();
|
||
$view->content->ivals = $device_templates_model->get_value();
|
||
$view->content->active_links_grid = $active_links_grid;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
... | ... | |
NULL => '---- ' . __('Select type') . ' ----'
|
||
) + $et_model->get_values(Enum_type_Model::DEVICE_TYPE_ID);
|
||
|
||
// Device active links
|
||
$device_active_links_model = new Device_active_link_Model();
|
||
|
||
$all_active_links = $device_active_links_model->get_all_active_links();
|
||
|
||
$active_links = array();
|
||
|
||
foreach($all_active_links AS $active_link)
|
||
{
|
||
if (!$active_link->name)
|
||
$active_links[$active_link->id] = $active_link->title;
|
||
else
|
||
$active_links[$active_link->id] = $active_link->name.' ('.$active_link->title.')';
|
||
}
|
||
|
||
// form
|
||
$form = new Forge();
|
||
|
||
... | ... | |
$form->checkbox('default')
|
||
->label('Default for this device type?');
|
||
|
||
$form->dropdown('active_links[]')
|
||
->label('Device active links')
|
||
->options($active_links)
|
||
->multiple('multiple')
|
||
->size(10);
|
||
|
||
// eth
|
||
|
||
$eth_form = $form->group('Ethernet interfaces');
|
||
... | ... | |
$tdefault->save();
|
||
}
|
||
}
|
||
|
||
|
||
// map to device active links
|
||
$device_active_links_model->map_device_to_active_links(
|
||
$device_template_model,
|
||
$form_data['active_links'],
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
// clean
|
||
unset($vals);
|
||
unset($form_data);
|
||
... | ... | |
// values
|
||
$ivals = $device_template_model->get_value();
|
||
|
||
// Device active links
|
||
$device_active_links_model = new Device_active_link_Model();
|
||
|
||
$all_active_links = $device_active_links_model->get_all_active_links();
|
||
$all_selected_active_link = $device_active_links_model->get_device_active_links(
|
||
$device_templates_id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
$active_links = array();
|
||
|
||
foreach($all_active_links AS $active_link)
|
||
{
|
||
if (!$active_link->name)
|
||
$active_links[$active_link->id] = $active_link->title;
|
||
else
|
||
$active_links[$active_link->id] = $active_link->name.' ('.$active_link->title.')';
|
||
}
|
||
|
||
$selected_active_links = array();
|
||
|
||
foreach ($all_selected_active_link AS $active_link)
|
||
{
|
||
$selected_active_links[] = $active_link->id;
|
||
}
|
||
|
||
// form
|
||
$form = new Forge('device_templates/edit/' . $device_templates_id);
|
||
|
||
... | ... | |
->label('Default for this device type?')
|
||
->checked($device_template_model->default);
|
||
|
||
$form->dropdown('active_links[]')
|
||
->label('Device active links')
|
||
->options($active_links)
|
||
->selected($selected_active_links)
|
||
->multiple('multiple')
|
||
->size(10);
|
||
|
||
|
||
// eth
|
||
|
||
$eth_form = $form->group('Ethernet interfaces');
|
||
... | ... | |
$tdefault->save();
|
||
}
|
||
}
|
||
|
||
$device_active_links_model->unmap_device_from_active_links(
|
||
$device_templates_id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
$device_active_links_model->map_device_to_active_links(
|
||
$device_templates_id,
|
||
$form_data['active_links'],
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
);
|
||
|
||
// clean
|
||
unset($vals);
|
freenetis/branches/1.1/application/controllers/devices.php | ||
---|---|---|
$grid->order_link_field('user_id')
|
||
->link('users/show', 'user_login');
|
||
|
||
if ($this->acl_check_view('Device_active_links_Controller', 'display_device_active_links'))
|
||
{
|
||
$grid->callback_field('device_grid')
|
||
->label('Device active links')
|
||
->callback('callback::device_active_links');
|
||
}
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Devices_Controller', 'devices'))
|
||
... | ... | |
->label('Subnet');
|
||
}
|
||
|
||
if ($this->acl_check_view('Device_active_links_Controller', 'display_device_active_links'))
|
||
{
|
||
$base_grid->callback_field('show_by_user')
|
||
->label('Device active links')
|
||
->callback('callback::device_active_links');
|
||
}
|
||
|
||
$actions = $base_grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Devices_Controller', 'devices', $user->member_id))
|
||
... | ... | |
|
||
$grid_device_engineers->datasource($de);
|
||
|
||
$active_links_model = new Device_active_link_Model();
|
||
|
||
$active_links = $active_links_model->get_device_active_links($device_id);
|
||
|
||
// device admins
|
||
$device_admin_model = new Device_admin_Model();
|
||
$da = $device_admin_model->get_device_admins($device_id);
|
||
... | ... | |
$view->content->gpsx = !empty($gps) ? $gps_result->gpsx : '';
|
||
$view->content->gpsy = !empty($gps) ? $gps_result->gpsy : '';
|
||
$view->content->lang = Config::get('lang');
|
||
$view->content->active_links = $active_links;
|
||
$view->render(TRUE);
|
||
} // end of show
|
||
|
||
... | ... | |
$arr_engineers[$engineer->id] = $engineer->get_full_name_with_login();
|
||
}
|
||
|
||
// Device active links
|
||
$device_active_links_model = new Device_active_link_Model();
|
||
|
||
$all_active_links = $device_active_links_model->get_all_active_links();
|
||
|
||
$active_links = array();
|
||
|
||
foreach($all_active_links AS $active_link)
|
||
{
|
||
if (!$active_link->name)
|
||
$active_links[$active_link->id] = $active_link->title;
|
||
else
|
||
$active_links[$active_link->id] = $active_link->name.' ('.$active_link->title.')';
|
||
}
|
||
|
||
// forge form
|
||
$form = new Forge();
|
||
|
||
... | ... | |
->mode('simple')
|
||
->label('Comment');
|
||
|
||
$group_device_details->dropdown('active_links[]')
|
||
->label('Device active links')
|
||
->options($active_links)
|
||
->multiple('multiple')
|
||
->size(10);
|
||
|
||
if (Settings::get('finance_enabled'))
|
||
{
|
||
$group_payment = $form->group('Device repayments')->visible(FALSE);
|
||
... | ... | |
}
|
||
|
||
$device->comment = $group_device_details->device_comment->value; // not escaped
|
||
|
||
|
||
// address point ///////////////////////////////////////////////////
|
||
|
||
// gps
|
||
... | ... | |
|
||
$device->address_point_id = $ap->id;
|
||
$device->save_throwable();
|
||
|
||
|
||
// device engineer ////////////////////////////////////////////
|
||
|
||
$device_engineer = new Device_engineer_Model();
|
||
... | ... | |
);
|
||
}
|
||
|
||
// saves active links
|
||
if ($form_data['active_links'])
|
||
{
|
||
$active_links = $form_data['active_links'];
|
||
|
||
foreach ($active_links AS $al)
|
||
{
|
||
$device_active_links_model->map_devices_to_active_link(array($device->id), $al);
|
||
}
|
||
}
|
||
|
||
// done ////////////////////////////////////////////////////
|
||
$dm->transaction_commit();
|
||
|
||
... | ... | |
NULL => '----- '.__('select town').' -----'
|
||
) + ORM::factory('town')->select_list_with_quater();
|
||
|
||
// Device active links
|
||
$device_active_links_model = new Device_active_link_Model();
|
||
|
||
$all_active_links = $device_active_links_model->get_all_active_links();
|
||
|
||
$device_active_links = $device_active_links_model->get_device_active_links($device_id);
|
||
|
||
$active_links = array();
|
||
|
||
foreach($all_active_links AS $active_link)
|
||
{
|
||
if (!$active_link->name)
|
||
$active_links[$active_link->id] = $active_link->title;
|
||
else
|
||
$active_links[$active_link->id] = $active_link->name.' ('.$active_link->title.')';
|
||
}
|
||
|
||
$selected_active_links = array();
|
||
|
||
foreach ($device_active_links AS $active_link)
|
||
{
|
||
$selected_active_links[] = $active_link->id;
|
||
}
|
||
|
||
// form
|
||
$form = new Forge('devices/edit/' . $device_id);
|
||
|
||
... | ... | |
->label('Comment')
|
||
->value($device->comment);
|
||
|
||
$group_device_details->dropdown('active_links[]')
|
||
->label('Device active links')
|
||
->options($active_links)
|
||
->selected($selected_active_links)
|
||
->multiple('multiple')
|
||
->size(10);
|
||
|
||
|
||
if (Settings::get('finance_enabled'))
|
||
{
|
||
$group_payment = $form->group('Device repayments')->visible($device->price > 0);
|
||
... | ... | |
$member->get_credit_account()->id
|
||
);
|
||
}
|
||
|
||
// update device active links
|
||
$device_active_links_model->unmap_device_from_active_links($device_id);
|
||
$device_active_links_model->map_device_to_active_links($device_id, $form_data['active_links']);
|
||
|
||
unset($form_data);
|
||
|
||
|
||
$device->transaction_commit();
|
||
status::success('Device has been successfully updated.');
|
||
url::redirect(Path::instance()->previous());
|
freenetis/branches/1.1/application/controllers/json.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* AJAX function for loading device template active links
|
||
*
|
||
* @author David Raška
|
||
*/
|
||
public function get_device_template_active_links()
|
||
{
|
||
$template_id = $this->input->get('template');
|
||
$device_active_link_model = new Device_active_link_Model();
|
||
|
||
$templates = $device_active_link_model->get_device_active_links(
|
||
$template_id,
|
||
Device_active_link_Model::TYPE_TEMPLATE
|
||
)->result_array();
|
||
|
||
if ($templates)
|
||
{
|
||
echo json_encode($templates);
|
||
}
|
||
else
|
||
{
|
||
echo json_encode(array());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Callback AJAX function to get only device templates of choosen type of
|
||
* device to dropdown
|
||
*
|
freenetis/branches/1.1/application/helpers/callback.php | ||
---|---|---|
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Replaces {ip_address} tag with device's first IP address
|
||
*
|
||
* @param string $url_pattern URL pattern
|
||
* @param integer $device_id Device ID
|
||
* @return string
|
||
*/
|
||
public static function device_active_link_url_prepare($url_pattern, $device_id)
|
||
{
|
||
$ip_address_model = new Ip_address_Model();
|
||
$ips = $ip_address_model->get_ip_addresses_of_device($device_id);
|
||
|
||
$ip = $ips->current()->ip_address;
|
||
|
||
if (!$ip)
|
||
{
|
||
return $url_pattern;
|
||
}
|
||
else
|
||
{
|
||
return str_replace('{ip_address}', $ip, $url_pattern);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Callback for printing device's active links
|
||
*
|
||
* @param object $item
|
||
* @param string $name
|
||
*/
|
||
public static function device_active_links($item, $name)
|
||
{
|
||
$device_active_links_model = new Device_active_link_Model();
|
||
|
||
$active_links = $device_active_links_model->get_device_active_links($item->id);
|
||
|
||
$links = array();
|
||
|
||
foreach ($active_links AS $al)
|
||
{
|
||
if (($name == 'show_by_user' && $al->show_in_user_grid) ||
|
||
($name == 'device_grid' && $al->show_in_grid))
|
||
{
|
||
$url = callback::device_active_link_url_prepare($al->url_pattern, $item->id);
|
||
|
||
$links[] = html::anchor(
|
||
$url,
|
||
($al->name? $al->name : $url),
|
||
array
|
||
(
|
||
'title' => $al->title,
|
||
)
|
||
);
|
||
}
|
||
}
|
||
|
||
echo implode('<br>', $links);
|
||
}
|
||
}
|
freenetis/branches/1.1/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'add new contact' => 'Přidat nový kontakt',
|
||
'add new credit account' => 'Přidat nový kreditní účet',
|
||
'add new device' => 'Přidat nové zařízení',
|
||
'add new device active link' => 'Přidat nový aktivní odkaz zařízení',
|
||
'add new device admin' => 'Přidat nového správce zařízení',
|
||
'add new device engineer' => 'Přidat nového technika zařízení',
|
||
'add new device for user' => 'Přidat nové zařízení pro uživatele',
|
||
... | ... | |
'details' => 'Detaily',
|
||
'details of' => 'Detaily',
|
||
'device' => 'Zařízení',
|
||
'device active link' => 'Aktivní odkaz zařízení',
|
||
'device active link has been successfully deleted' => 'Aktivní odkaz zařízení byl úspěšně smazán.',
|
||
'device active links' => 'Aktivní odkazy zařízení',
|
||
'device admin has been successfully removed' => 'Správce zařízení byl úspěšně odebrán.',
|
||
'device admin has been successfully updated' => 'Správce zařízení byl úspěšně upraven.',
|
||
'device admin is successfully saved' => 'Správce zařízení byl úspěšně uložen.',
|
||
... | ... | |
'edit comment' => 'Upravit komentář',
|
||
'edit contact' => 'Upravit kontakt',
|
||
'edit device' => 'Upravit zařízení',
|
||
'edit device active link' => 'Upravit aktivní odkaz zařízení',
|
||
'edit device admins' => 'Upravit správce zařízení',
|
||
'edit device template' => 'Upravit šablonu zařízení',
|
||
'edit enum type' => 'Upravit výčet',
|
||
... | ... | |
'next update' => 'příští aktualizace',
|
||
'nineth-degree certified engineers' => 'Certifikování technici devátého stupně',
|
||
'no' => 'ne',
|
||
'no devices' => 'Žádná zařízení',
|
||
'no changes in last 30 days' => 'Žádné změny v posledních 30 dnech',
|
||
'no items found' => 'Nebyly nalezeny žádné položky.',
|
||
'no redirection' => 'Žádné přesměrování',
|
||
... | ... | |
'show e-mail message' => 'Zobrazit e-mailovou zprávu',
|
||
'show form items' => 'Zobrazit položky formuláře',
|
||
'show help' => 'Zobrazit nápovědu',
|
||
'show in grid' => 'Zobrazit v tabulce zařízení',
|
||
'show in user grid' => 'Zobrazit v tabulce zařízení uživatele',
|
||
'show interface' => 'Zobrazit rozhraní',
|
||
'show invoice' => 'Zobrazit fakturu',
|
||
'show invoice item' => 'Zobrazit položku faktury',
|
||
... | ... | |
'upload device templates' => 'Nahrát šablony zařízení',
|
||
'url' => 'URL',
|
||
'url addresses without index' => 'URL adresy bez index.php.',
|
||
'url pattern' => 'Šablona URL',
|
||
'url settings' => 'Nastavení URL',
|
||
'url to redirect after canceling message' => 'URL k přesměrování po zrušení zprávy',
|
||
'use' => 'Použít',
|
freenetis/branches/1.1/application/libraries/MY_Controller.php | ||
---|---|---|
'administration');
|
||
}
|
||
|
||
// list of device_templates
|
||
if (Settings::get('networks_enabled') &&
|
||
$this->acl_check_view('Device_active_links_Controller', 'active_links'))
|
||
{
|
||
$menu->addItem(
|
||
'device_active_links/show_all', __('Device active links'),
|
||
'administration');
|
||
}
|
||
|
||
// list of approval templates
|
||
if (Settings::get('approval_enabled') &&
|
||
$this->acl_check_view('approval', 'templates'))
|
freenetis/branches/1.1/application/models/device.php | ||
---|---|---|
|
||
protected $has_many = array
|
||
(
|
||
'ifaces', 'device_admins', 'device_engineers', 'connection_requests'
|
||
'ifaces', 'device_admins', 'device_engineers', 'connection_requests', 'device_active_links'
|
||
);
|
||
|
||
protected $belongs_to = array
|
freenetis/branches/1.1/application/models/device_active_link.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is release 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/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
*
|
||
* @package Model
|
||
*
|
||
* @property integer $id
|
||
* @property string $url_pattern
|
||
* @property string $name
|
||
* @property string $title
|
||
* @property integer $show_in_user_grid
|
||
* @property integer $show_in_grid
|
||
*
|
||
* @author David Raška <jeffraska@gmail.com>
|
||
*/
|
||
class Device_active_link_Model extends ORM
|
||
{
|
||
const TYPE_DEVICE = 1;
|
||
const TYPE_TEMPLATE = 2;
|
||
|
||
protected $has_many = array
|
||
(
|
||
'device_active_links'
|
||
);
|
||
|
||
/**
|
||
* Count of all device active links
|
||
* @param array $filter_values
|
||
* @return integer
|
||
*/
|
||
public function count_all_active_links($filter_sql = '')
|
||
{
|
||
$where = '';
|
||
|
||
// filter
|
||
if ($filter_sql != '')
|
||
$where = "WHERE $filter_sql";
|
||
|
||
// query
|
||
return $this->db->query("
|
||
SELECT *
|
||
FROM device_active_links
|
||
$where
|
||
")->count();
|
||
}
|
||
|
||
/**
|
||
* Get all device active links
|
||
*
|
||
* @param array $params
|
||
* @return Mysql_Result
|
||
*/
|
||
public function get_all_active_links($params = array())
|
||
{
|
||
// default params
|
||
$default_params = array
|
||
(
|
||
'order_by' => 'id',
|
||
'order_by_direction' => 'asc'
|
||
);
|
||
|
||
$params = array_merge($default_params, $params);
|
||
|
||
$conds = array();
|
||
|
||
// filter
|
||
if (isset($params['filter_sql']) && $params['filter_sql'] != '')
|
||
$conds[] = $params['filter_sql'];
|
||
|
||
$where = count($conds) ? 'WHERE '.implode(' AND ', $conds) : '';
|
||
|
||
$order_by = $this->db->escape_column($params['order_by']);
|
||
|
||
// order by direction check
|
||
if (strtolower($params['order_by_direction']) != 'desc')
|
||
$order_by_direction = 'asc';
|
||
else
|
||
$order_by_direction = 'desc';
|
||
|
||
if (isset($params['limit']) && isset($params['offset']))
|
||
$limit = "LIMIT " . intval($params['offset']) . ", " . intval($params['limit']);
|
||
else
|
||
$limit = "";
|
||
|
||
// query
|
||
return $this->db->query("
|
||
SELECT dal.*, dalm.*, COUNT(*) AS devices_count
|
||
FROM device_active_links AS dal
|
||
LEFT JOIN device_active_links_map AS dalm ON dal.id = dalm.device_active_link_id
|
||
$where
|
||
GROUP BY dal.id
|
||
ORDER BY $order_by $order_by_direction
|
||
$limit
|
||
");
|
||
}
|
||
|
||
/**
|
||
* Maps devices to device active link
|
||
*
|
||
* @param array $devices Array of device IDs to map
|
||
* @param integer $dal_id Device active link ID
|
||
* @return Database_result
|
||
*/
|
||
public function map_devices_to_active_link($devices = NULL, $dal_id = NULL,
|
||
$type = Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
if (!$devices || empty($devices))
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
foreach ($devices AS $device)
|
||
{
|
||
$this->db->query("
|
||
INSERT INTO device_active_links_map (device_active_link_id, device_id, type)
|
||
VALUES (?, ?, ?)
|
||
", $dal_id, $device, $type);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Unmaps devices from device active link
|
||
*
|
||
* @param integer $dal_id Device active link ID
|
||
* @return Database_result
|
||
*/
|
||
public function unmap_devices_from_active_link($dal_id = NULL,
|
||
$type = Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
$this->db->query("
|
||
DELETE FROM device_active_links_map
|
||
WHERE device_active_link_id = ? AND type = ?
|
||
", $dal_id, $type);
|
||
}
|
||
|
||
/**
|
||
* Maps device to device active links
|
||
*
|
||
* @param integer $device_id Device ID
|
||
* @param array $dal_ids Array of device active link IDs
|
||
* @return Database_result
|
||
*/
|
||
public function map_device_to_active_links($device_id = NULL, $dal_ids = NULL,
|
||
$type = Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
if (!$device_id || !$dal_ids || empty($dal_ids))
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
foreach ($dal_ids AS $id)
|
||
{
|
||
$this->db->query("
|
||
INSERT INTO device_active_links_map (device_active_link_id, device_id, type)
|
||
VALUES (?, ?, ?)
|
||
", $id, $device_id, $type);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Unmaps device from device active links
|
||
*
|
||
* @param integer $device_id Device ID
|
||
* @return Database_result
|
||
*/
|
||
public function unmap_device_from_active_links($device_id = NULL,
|
||
$type = Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
if (!$device_id)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
$this->db->query("
|
||
DELETE FROM device_active_links_map
|
||
WHERE device_id = ? AND type = ?
|
||
", $device_id, $type);
|
||
}
|
||
|
||
/**
|
||
* Return all devices using given active link
|
||
*
|
||
* @param integer $dal_id Device active link ID
|
||
* @return Mysql_result
|
||
*/
|
||
public function get_active_link_devices($dal_id = NULL,
|
||
$type = Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
if (!$dal_id)
|
||
{
|
||
$dal_id = $this->id;
|
||
}
|
||
|
||
if ($type == Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
return $this->db->query("
|
||
SELECT d.*
|
||
FROM device_active_links_map dalm
|
||
LEFT JOIN devices AS d ON d.id = dalm.device_id
|
||
WHERE dalm.device_active_link_id = ? AND dalm.type = ?
|
||
", $dal_id, $type);
|
||
}
|
||
else
|
||
{
|
||
return $this->db->query("
|
||
SELECT dt.*
|
||
FROM device_active_links_map dalm
|
||
LEFT JOIN device_templates AS dt ON dt.id = dalm.device_id
|
||
WHERE dalm.device_active_link_id = ? AND dalm.type = ?
|
||
", $dal_id, $type);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Returns active links used by device
|
||
*
|
||
* @param type $device_id Device ID
|
||
* @return null
|
||
*/
|
||
public function get_device_active_links($device_id = NULL,
|
||
$type = Device_active_link_Model::TYPE_DEVICE)
|
||
{
|
||
if (!$device_id)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
return $this->db->query("
|
||
SELECT dal.*
|
||
FROM device_active_links_map AS dalm
|
||
LEFT JOIN device_active_links AS dal ON dal.id = dalm.device_active_link_id
|
||
WHERE dalm.device_id = ? AND dalm.type = ?
|
||
", $device_id, $type);
|
||
}
|
||
}
|
freenetis/branches/1.1/application/views/device_active_links/add.php | ||
---|---|---|
<h2><?php echo $headline ?></h2>
|
||
|
||
<br /><?php echo $form ?><br />
|
freenetis/branches/1.1/application/views/device_active_links/show.php | ||
---|---|---|
<h2><?php echo $headline ?></h2>
|
||
<br />
|
||
|
||
<?php
|
||
|
||
$links = array();
|
||
|
||
if ($this->acl_check_edit('Device_active_links_Controller', 'active_links'))
|
||
$links[] = html::anchor('device_active_links/edit/'.$active_link->id, __('Edit'));
|
||
|
||
if ($this->acl_check_delete('Device_active_links_Controller', 'active_links'))
|
||
$links[] = html::anchor('device_active_links/delete/'.$active_link->id, __('Delete'), array('class' => 'delete_link'));
|
||
|
||
echo implode(' | ', $links)
|
||
?>
|
||
<br />
|
||
<br />
|
||
|
||
<table class="extended clear" cellspacing="0" style="float:left;word-wrap: break-word;">
|
||
<tr>
|
||
<th><?php echo __('ID') ?></th>
|
||
<td><?php echo $active_link->id ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo __('URL pattern') ?></th>
|
||
<td><?php echo $active_link->url_pattern ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo __('Name') ?></th>
|
||
<td><?php echo $active_link->name ?></td>
|
||
</tr>
|
||
<tr>
|
||
<th><?php echo __('Title') ?></th>
|
||
<td><?php echo $active_link->title ?></td>
|
||
</tr>
|
||
|
||
</table>
|
||
|
||
<div class="clear"></div>
|
||
<br />
|
||
|
||
<h3><?php echo __('Devices') ?></h3>
|
||
|
||
<div id="devices-grid">
|
||
<?php echo $devices_grid ?>
|
||
</div>
|
||
|
||
<br />
|
||
<h3><?php echo __('Device templates') ?></h3>
|
||
|
||
<div id="devices-grid">
|
||
<?php echo $device_templates_grid ?>
|
||
</div>
|
freenetis/branches/1.1/application/views/device_templates/show.php | ||
---|---|---|
<td><?php foreach ($ivals[Iface_Model::TYPE_INTERNAL]['items'] as $item) echo ($item['name']) ? $item['name'] . ', ' : '' ?></td>
|
||
</tr>
|
||
</table>
|
||
|
||
<?php if ($this->acl_check_view('Device_active_links_Controller', 'active_links')): ?>
|
||
<br /><h3><?php echo __('Device active links') ?></h3>
|
||
<?php echo $active_links_grid; ?>
|
||
<?php endif; ?>
|
freenetis/branches/1.1/application/views/devices/show.php | ||
---|---|---|
<th><?php echo __('Comment') ?></th>
|
||
<td><?php echo $device->comment ?></td>
|
||
</tr>
|
||
<?php if ($this->acl_check_view('Device_active_links_Controller', 'display_device_active_links') && $active_links):?>
|
||
<tr>
|
||
<th><?php echo __('Device active links') ?></th>
|
||
<td>
|
||
<?php foreach ($active_links AS $al): $url = callback::device_active_link_url_prepare($al->url_pattern, $device->id) ?>
|
||
<a href="<?php echo $url ?>" title="<?php echo $al->title ?>"><?php echo ($al->name? $al->name : $url) ?></a><br>
|
||
<?php endforeach; ?>
|
||
</td>
|
||
</tr>
|
||
<?php endif; ?>
|
||
</table>
|
||
|
||
<?php if (!empty($gps)): ?>
|
Také k dispozici: Unified diff
Nove:
- closes #602: Implementace aktivnich odkazu zarizeni