Revize 120
Přidáno uživatelem Michal Kliment před asi 16 roky(ů)
freenetis/trunk/kohana/application/controllers/device_admins.php | ||
---|---|---|
<?php
|
||
class Device_admins_Controller extends Controller {
|
||
|
||
function index()
|
||
{
|
||
|
||
// url::redirect(url_lang::base().'ifaces/show_all');
|
||
}
|
||
|
||
|
||
|
||
//=============================================================================
|
||
//----- SHOW_ALL --------------------------------------------------------------
|
||
//=============================================================================
|
||
/* function show_all($limit_results = 200, $order_by = 'id', $order_by_direction = 'ASC')
|
||
{
|
||
//---- delete session device ----
|
||
$this->session->del('ssDevice_id');
|
||
$this->session->del('ssIface_id');
|
||
|
||
$iface_model = new Iface_Model();
|
||
|
||
$total_ifaces = $iface_model->count_all_ifaces(); // count all members in database
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->get('record_per_page'))) $limit_results = (int) $this->input->get('record_per_page');
|
||
|
||
$url_array = explode('/', trim(url::current(), '/'));
|
||
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
|
||
unset($url_array);
|
||
$sql_offset = ($sql_offset>$total_ifaces) ? 0 : $sql_offset;
|
||
|
||
//die();
|
||
|
||
$query = $iface_model->select(array('devices.name as device_name', 'segments.name as segment_name', 'ifaces.*'))
|
||
->join('devices', 'devices.id = ifaces.device_id')
|
||
->join('segments', 'segments.id = ifaces.segment_id', NULL, 'LEFT')
|
||
->orderby($order_by,$order_by_direction)
|
||
->limit($limit_results,$sql_offset)
|
||
->find_all();
|
||
|
||
$grid = new Grid(url_lang::base().'ifaces', null,array(
|
||
//'separator' => '<br />-----------',
|
||
//'use_paginator' => false,
|
||
//'use_selector' => false,
|
||
'current' => $limit_results, // current selected 'records_per_page' value
|
||
'selector_increace' => 200, // increace
|
||
'selector_min' => 200, // minimum where selector start
|
||
'selector_max_multiplier' => 10,
|
||
'base_url' => Config::item('locale.lang').'/ifaces/show_all/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
|
||
'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality
|
||
'total_items' => $total_ifaces, // use db count query here of course
|
||
'items_per_page' => $limit_results, // it may be handy to set defaults for stuff like this in config/pagination.php
|
||
'style' => 'classic',
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results
|
||
));
|
||
|
||
$grid->add_new_button(url_lang::base().'ifaces/add', url_lang::lang('texts.Add new interface'));
|
||
$grid->order_field('id')->label('ID');
|
||
$grid->order_field('name')->label(url_lang::lang('texts.name'));
|
||
$grid->order_field('device_name')->label(url_lang::lang('texts.Device name'));
|
||
$grid->order_field('segment_name')->label(url_lang::lang('texts.Segment name'));
|
||
$grid->order_field('comment')->label(url_lang::lang('texts.comment'));
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Show')) ->url(url_lang::base().'ifaces/show') ->action(url_lang::lang('texts.Show'))->class('center');
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Edit')) ->url(url_lang::base().'ifaces/edit') ->action(url_lang::lang('texts.Edit'))->class('center');
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Delete')) ->url('delete') ->action(url_lang::lang('texts.Delete'))->class('center');
|
||
$grid->datasource( $query );
|
||
$this->template->content = $grid;
|
||
|
||
|
||
$view = new View('template');
|
||
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Interfaces list');
|
||
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('show_all');
|
||
$view->content->table = $this->template->content;
|
||
$view->content->headline = url_lang::lang('texts.Interfaces list');
|
||
|
||
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
}
|
||
//----- end SHOW_ALL ----------------------------------------------------------
|
||
//=============================================================================
|
||
*/
|
||
|
||
|
||
//=============================================================================
|
||
//----- SHOW ------------------------------------------------------------------
|
||
//=============================================================================
|
||
/* function show($device_id = null)
|
||
{
|
||
$ssDevice_id = $this->session->get('ssDevice_id');
|
||
|
||
$iface = new Iface_Model($iface_id);
|
||
if (is_null($iface->segment_id)) $iface->segment_id="NULL";
|
||
if (!isset($iface_id) || $iface->id == 0) {
|
||
Controller::error();
|
||
}
|
||
|
||
$this->session->set('ssIface_id',$iface->id);
|
||
|
||
$this->session->del('ssVlan_iface_id');
|
||
|
||
//----------- list of IP ADDRESSES ---------------
|
||
$ip_model = new Ip_address_Model();
|
||
|
||
//$query = $iface_model->select(array('devices.name as device_name', 'segments.name as segment_name', 'ifaces.*'))->join('devices', 'devices.id = ifaces.device_id')->join('segments', 'segments.id = ifaces.segment_id')->orderby('id','ASC')->find_all_by_device_id($iface_id);
|
||
$query = $ip_model->select(array('ip_addresses.id','ip_addresses.IP_address','subnets.name as subnet_name'))
|
||
->join('subnets','subnets.id=ip_addresses.subnet_id', NULL, 'LEFT')
|
||
->orderby('id','ASC')
|
||
->find_all_by_iface_id($iface_id);
|
||
$grid_ip_addresses = new Grid(url_lang::base().'ifaces', null,array(
|
||
'use_paginator' => false,
|
||
'use_selector' => false
|
||
));
|
||
|
||
$grid_ip_addresses->add_new_button(url_lang::base().'ip_addresses/add', url_lang::lang('texts.Add new IP address'));
|
||
$grid_ip_addresses->field('id')->label('ID')->class('center');
|
||
$grid_ip_addresses->field('IP_address')->label(url_lang::lang('texts.IP address'));
|
||
$grid_ip_addresses->field('subnet_name')->label(url_lang::lang('texts.Subnet name'));
|
||
$grid_ip_addresses->action_field('id')->label(url_lang::lang('texts.Show')) ->url(url_lang::base().'ip_addresses/show') ->action(url_lang::lang('texts.Show'))->class('center');
|
||
$grid_ip_addresses->action_field('id')->label(url_lang::lang('texts.Edit')) ->url(url_lang::base().'ip_addresses/edit') ->action(url_lang::lang('texts.Edit'))->class('center');
|
||
$grid_ip_addresses->action_field('id')->label(url_lang::lang('texts.Delete')) ->url(url_lang::base().'ip_addresses/delete') ->action(url_lang::lang('texts.Delete'))->class('center');
|
||
$grid_ip_addresses->datasource( $query );
|
||
|
||
|
||
//----------- list of VLAN INTERFACES ---------------
|
||
$VLAN_iface_model = new Vlan_iface_Model();
|
||
|
||
$query = $VLAN_iface_model->select(array('id','name'))
|
||
->orderby('id','ASC')
|
||
->find_all_by_iface_id($iface_id);
|
||
|
||
$grid_VLAN_ifaces = new Grid(url_lang::base().'ifaces', null,array(
|
||
'use_paginator' => false,
|
||
'use_selector' => false
|
||
));
|
||
|
||
$grid_VLAN_ifaces->add_new_button(url_lang::base().'vlan_ifaces/add', url_lang::lang('texts.Add new VLAN interface'));
|
||
$grid_VLAN_ifaces->field('id')->label('ID')->class('center');
|
||
$grid_VLAN_ifaces->field('name')->label(url_lang::lang('texts.Name'));
|
||
$grid_VLAN_ifaces->action_field('id')->label(url_lang::lang('texts.Show')) ->url(url_lang::base().'vlan_ifaces/show') ->action(url_lang::lang('texts.Show'))->class('center');
|
||
$grid_VLAN_ifaces->action_field('id')->label(url_lang::lang('texts.Edit')) ->url(url_lang::base().'vlan_ifaces/edit') ->action(url_lang::lang('texts.Edit'))->class('center');
|
||
$grid_VLAN_ifaces->action_field('id')->label(url_lang::lang('texts.Delete')) ->url('delete') ->action(url_lang::lang('texts.Delete'))->class('center');
|
||
$grid_VLAN_ifaces->datasource( $query );
|
||
|
||
if ($ssDevice_id) $link_back = html::anchor(url_lang::base().'devices/show/'.$ssDevice_id, url_lang::lang('texts.Back to device parameters'));
|
||
else $link_back = html::anchor(url_lang::base().'ifaces/show_all', url_lang::lang('texts.Back to interfaces list'));
|
||
|
||
|
||
$view = new View('template');
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Interface detail').' - '.$iface->name;
|
||
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('show_iface');
|
||
$view->content->iface = $iface;
|
||
$view->content->headline = url_lang::lang('texts.Interface detail').' - '.$iface->name;
|
||
$view->content->table_ip_addresses = $grid_ip_addresses;
|
||
$view->content->table_VLAN_ifaces = $grid_VLAN_ifaces;
|
||
$view->content->link_back = $link_back;
|
||
|
||
|
||
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
}
|
||
//----- end SHOW --------------------------------------------------------------
|
||
//=============================================================================
|
||
|
||
*/
|
||
|
||
//=============================================================================
|
||
//----- ADD -------------------------------------------------------------------
|
||
//=============================================================================
|
||
function add()
|
||
{
|
||
$ssDevice_id = $this->session->get('ssDevice_id');
|
||
|
||
|
||
$form = new Forge(url_lang::base()."device_admins/add/", '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$form->group('')->label(url_lang::lang('texts.Basic data'));
|
||
|
||
|
||
if ($ssDevice_id)
|
||
{
|
||
$device = new Device_Model($ssDevice_id);
|
||
$form->dropdown('device_id')->label(url_lang::lang('texts.Device name'))->options(array($ssDevice_id => $device->name))->rules('required');
|
||
}
|
||
|
||
else
|
||
{
|
||
|
||
$device_model = new Device_Model();
|
||
$devices = $device_model->select(array('id','name'))->orderby('name')->find_all();
|
||
$arr_devices[0] = '----- '.url_lang::lang('texts.select device').' -----';
|
||
foreach ($devices as $device) {
|
||
$arr_devices[$device->id] = $device->name;
|
||
}
|
||
$form->dropdown('device_id')->label(url_lang::lang('texts.Device name'))->options($arr_devices)->rules('required');
|
||
}
|
||
|
||
$user_model = new User_Model();
|
||
|
||
$device_admin_model = new Device_admin_Model();
|
||
|
||
if($ssDevice_id) $admins = $device_admin_model->find_all_by_device_id($ssDevice_id);
|
||
else $admins = array();
|
||
|
||
$users = $user_model->find_all();
|
||
$arr_users[0] = '----- '.url_lang::lang('texts.select user').' -----';
|
||
foreach($users as $user) {
|
||
$clause = 1;
|
||
foreach($admins as $admin) if($admin->user->id == $user->id) $clause = 0;
|
||
if($clause == 1) $arr_users[$user->id] = $user->surname.' '.$user->name.' - '.$user->login;
|
||
}
|
||
asort($arr_users);
|
||
|
||
$form->dropdown('user_id')->label(url_lang::lang('texts.user'))->options($arr_users)->rules('required');
|
||
|
||
$form->submit('submit')->value(url_lang::lang('texts.Save'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
$device_admin = new Device_admin_Model();
|
||
|
||
foreach($form_data as $key => $value)
|
||
{
|
||
$device_admin->$key = htmlspecialchars($value);
|
||
}
|
||
|
||
$device_id = $form_data['device_id'];
|
||
|
||
unset($form_data);
|
||
|
||
if ($device_admin->save()) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.New device admin is successfully saved.'));
|
||
url::redirect(url_lang::base().'devices/show/'.$device_id);
|
||
exit;
|
||
}
|
||
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
if ($ssDevice_id) $link_back = html::anchor(url_lang::base().'devices/show/'.$ssDevice_id, url_lang::lang('texts.Back to device parameters'));
|
||
// else $link_back = html::anchor(url_lang::base().'ifaces/show_all/', url_lang::lang('texts.Back to interfaces list'));
|
||
|
||
$view = new View('template');
|
||
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Add new device admin');
|
||
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('form');
|
||
$view->content->form = $form->html();
|
||
$view->content->link_back = $link_back;
|
||
$view->content->headline = url_lang::lang('texts.Add new device admin');
|
||
|
||
|
||
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
}
|
||
//----- end ADD ---------------------------------------------------------------
|
||
//=============================================================================
|
||
|
||
|
||
//=============================================================================
|
||
//----- EDIT ------------------------------------------------------------------
|
||
//=============================================================================
|
||
function edit($device_admin_id = null)
|
||
{
|
||
$ssDevice_id = $this->session->get('ssDevice_id');
|
||
|
||
$device_admin = new Device_admin_Model($device_admin_id);
|
||
|
||
if (!isset($device_admin_id) || $device_admin->id == 0) {
|
||
Controller::error();
|
||
}
|
||
|
||
$form = new Forge(url_lang::base()."device_admins/edit/".$device_admin_id, '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$form->group('')->label(url_lang::lang('texts.Basic data'));
|
||
|
||
|
||
|
||
|
||
/* if ($ssDevice_id)
|
||
{ */
|
||
$device = new Device_Model($device_admin->device_id);
|
||
$form->dropdown('device_id')->label(url_lang::lang('texts.Device name'))->options(array($device->id => $device->name))->rules('required');
|
||
/*}
|
||
|
||
else
|
||
{
|
||
|
||
$device_model = new Device_Model();
|
||
$devices = $device_model->select(array('id','name'))->orderby('name')->find_all();
|
||
$arr_devices[0] = '----- '.url_lang::lang('texts.select device').' -----';
|
||
foreach ($devices as $device) {
|
||
$arr_devices[$device->id] = $device->name;
|
||
}
|
||
$form->dropdown('device_id')->label(url_lang::lang('texts.Device name'))->options($arr_devices)->rules('required')->selected($iface->device_id);
|
||
}
|
||
*/
|
||
|
||
$user_model = new User_Model();
|
||
+ $admins = $device_admin->find_all_by_device_id($ssDevice_id);
|
||
|
||
|
||
|
||
$users = $user_model->find_all();
|
||
$arr_users = array();
|
||
foreach($users as $user) {
|
||
$clause = 1;
|
||
foreach($admins as $admin) if($admin->user->id == $user->id) $clause = 0;
|
||
if($user->id == $device_admin->user_id) $clause = 1;
|
||
if($clause == 1) $arr_users[$user->id] = $user->surname.' '.$user->name.' - '.$user->login;
|
||
}
|
||
asort($arr_users);
|
||
|
||
$form->dropdown('user_id')->label(url_lang::lang('texts.user'))->options($arr_users)->rules('required')->selected($device_admin->user_id);
|
||
|
||
|
||
$form->submit('submit')->value(url_lang::lang('texts.update'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
$device_admin = new Device_admin_Model($device_admin_id);
|
||
|
||
foreach($form_data as $key => $value)
|
||
{
|
||
$device_admin->$key = htmlspecialchars($value);
|
||
}
|
||
|
||
$device_id = $form_data['device_id'];
|
||
|
||
/*print_r($form_data);
|
||
die();*/
|
||
unset($form_data);
|
||
|
||
if ($device_admin->save()) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Device admin is successfully updated.'));
|
||
url::redirect(url_lang::base().'devices/show/'.$device_id);
|
||
exit;
|
||
}
|
||
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
if ($ssDevice_id) $link_back = html::anchor(url_lang::base().'devices/show/'.$ssDevice_id, url_lang::lang('texts.Back to device parameters'));
|
||
// else $link_back = html::anchor(url_lang::base().'ifaces/show_all/', url_lang::lang('texts.Back to interfaces list'));
|
||
|
||
|
||
$view = new View('template');
|
||
$view->header = new View('base/header');
|
||
$view->header->title = url_lang::lang('texts.Edit device admin');
|
||
$view->header->menu = Controller::render_menu();
|
||
|
||
$view->content = new View('form');
|
||
$view->content->form = $form->html();
|
||
$view->content->link_back = $link_back;
|
||
$view->content->headline = url_lang::lang('texts.Edit device admin');
|
||
|
||
|
||
$view->footer = new View('base/footer');
|
||
|
||
$view->render(TRUE);
|
||
}
|
||
//----- end EDIT --------------------------------------------------------------
|
||
//=============================================================================
|
||
|
||
|
||
|
||
}
|
||
|
||
?>
|
Také k dispozici: Unified diff
Pridan controller device_admin:
funkce add dovoluje pridavani adminu pro jednotlive zarizeni
funkce edit je pak dovoluje editovat