Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1397

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

Novinky:
- pridana podpora tagovanych a netagovanych VLANu, modu portu, port vlanu (#183)

Upravy:
- zpristupneni platebni kalkulacky i radnych clenum (#140)
- pridana moznost zmenit rozhrani IP adresy (#126)

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/texts.php
'port name' => 'Název portu',
'port number' => 'Číslo portu',
'port number already exist' => 'Číslo portu již existuje.',
'port vlan has to be in tagged vlans' => 'Port VLAN musí být mezi tagovanými VLANy.',
'port vlan has to be in untagged vlans' => 'Port VLAN musí být mezi netagovanými VLANy.',
'ports list' => 'Seznam portů',
'ports' => 'Porty',
'ports count' => 'Počet portů',
......
'table name' => 'Jméno tabulky',
'table prefix' => 'Prefix tabulek',
'tag_802_1q' => 'Tag 802.1Q',
'tagged vlans' => 'Tagované VLANy',
'tagged vlan' => 'Tagovaný VLAN',
'target website' => 'Cílový web pro přesměrování',
'tariff' => 'tarif',
'tariffs' => 'Tarify',
......
'there are no items yet' => 'Neobsahuje žádné záznamy.',
'there are not any unassigned admins' => 'Neexistují nepřiřazení správci',
'there are not any unassigned subnets' => 'Neexistují nepřiřazené podsítě',
'there is already some vlan with this tag' => 'Již existuje nějaký VLAN s tímto tagem.',
'third-degree certified engineers' => 'Certifikovaní technici třetího stupně',
'this account does not exist' => 'Tento účet neexistuje.',
'this approval template already contains approval type with the same priority' => 'Tato hlasovací šablona již obsahuje hlasovací typ se stejnou prioritou.',
......
'unknown' => 'Neznámý',
'unread' => 'Nepřečtená',
'unsent' => 'Neodeslaná',
'untagged vlans' => 'Netagované VLANy',
'until' => 'do',
'until user reading' => 'Do přečtení uživatelem',
'unlocked' => 'Odemčen',
......
'viewing of all records' => 'Prohlížení všech záznamů',
'viewing of own records' => 'Prohlížení vlastních záznamů',
'virus' => 'Počítačový vir',
'vlan can be only tagged or untagged' => 'VLAN může být buď tagovaný nebo netagovaný.',
'vlan count' => 'Počet VLANů',
'vlan detail' => 'Detail VLANu',
'vlan interface' => 'VLAN rozhraní',
freenetis/branches/testing/application/i18n/cs_CZ/help.php
'payment_notice_boundary' => 'Hranice po upozornění na placení je taková částka, pro kterou platí, že jakmile bude mít člen nižší stav kreditu než je tato částka, pak mu bude aktivováno příslušné přesměrování. Např. při hranici 300 Kč začne být člen s kreditem 299Kč a méně být informován o tom, že by měl zaplatit. Tuto informaci ovšem může člen zatím sám zrušit.',
'phone_invoice_user_lock' => 'Označí fakturu jako vyplněnou, čímž Vám zabrání další editaci a usnadní přehled o tom které faktury jste již vyplnil(a).',
'phone_invoice_user_unlock' => 'Odznačí fakturu jako vyplněnou, čímž Vám umožní její editaci.',
'port_vlan' => 'Port VLAN označuje výchozí VLAN portu.',
'price_tax' => 'Cena s DPH',
'project_subaccounts' => 'Projektový účet 221103 pro účetního představuje jeden účet. Zde jsou ovšem rozepsány všechny projektové podúčty z pohledu Freenetisu. Každý člen má právo vytvořit svůj projekt, který je v souladu se stanovami sdružení, může jít například o nějakou akci nebo školení. Cílem takovéhoto projektového podúčtu je, aby ostatní členové měli možnost zakladateli projektu přispět peníze ze svého kreditního účtu na realizaci projektu.',
'qos_high_priority_ip_addresses' => 'Jedná se o výčet adres s vysokou prioritou. Primárně je určeno pro IP adresy mimo síť (např. VoIP ústředny). Lze použít i pro vnitřní IP, ale nedoporučuje se - pro takové účely je vhodnější použít nastavení rychlosti přímo u člena. Každou adresu je nutno zapsat na samostatný řádek.',
freenetis/branches/testing/application/helpers/network.php
* @param integer $size
* @return string
*/
public static function size($size)
public static function size($size, $byte = TRUE)
{
// default unit is kiloByte
$unit = 'kB';
// default unit is kilo
$unit = 'k';
// size is too big
if ($size > 1024)
if ($size >= 1024)
{
// transforms to MegaByte
$unit = 'MB';
// transforms to Mega
$unit = 'M';
$size = round($size / 1024, 2);
// size is still too big
if ($size > 1024)
if ($size >= 1024)
{
// transforms to GigaByte
$unit = 'GB';
// transforms to Giga
$unit = 'G';
$size = round($size / 1024, 2);
}
}
$unit .= ($byte) ? 'B' : 'b';
return ($size) ? $size . ' ' . $unit : '0 ' . $unit;
}
freenetis/branches/testing/application/helpers/callback.php
* @param object $item
* @param string $name
*/
public static function bitrate_field ($item, $name)
public static function bitrate_field ($item, $name, $args = array())
{
echo network::size($item->bitrate/1024);
$byte = TRUE;
if (isset($args[0]))
$byte = $args[0];
echo network::size($item->bitrate/1024, $byte);
}
/**
......
echo html::image(
array
(
'src' => url::base().'media/images/icons/wireless_icon.png',
'src' => url::base().'media/images/icons/wireless.png',
'title' => __('Wireless')
)
);
......
echo html::image(
array
(
'src' => url::base().'media/images/icons/ethernet_icon.png',
'src' => url::base().'media/images/icons/ethernet.png',
'title' => __('Ethernet')
)
);
......
if (isset($item->more_ips) && $item->more_ips)
$class = 'more';
if ($item->ip_address_id)
if ((!isset($args[1]) || $args[1]) && $item->ip_address_id)
{
if (url_lang::current(1) == 'devices')
{
......
}
}
else if ($item->ip_address != '')
echo '<span style="color: green" class="'.$class.'" title="'.$title.'">'.$ip_address.'</span>';
{
if (!isset($args[2]) || $args[2])
echo '<span style="color: green" class="'.$class.'" title="'.$title.'">'.$ip_address.'</span>';
else
echo $ip_address;
}
else
echo '&nbsp';
}
......
}
/**
* Callback function to print mode of port
*
* @author Michal Kliment
* @param type $item
* @param type $name
*/
public function port_mode_field($item, $name)
{
echo Port_Model::get_mode($item->mode);
}
/**
* Callback function to print count of ports and grouped ports as title
*
* @author Michal Kliment
freenetis/branches/testing/application/models/device.php
$conds = array();
// filter
if ($params['filter_sql'] != '')
if (isset($params['filter_sql']) && $params['filter_sql'] != '')
$conds[] = $params['filter_sql'];
// user id
......
", $segment_id);
}
/**
* Returns all devices of member
*
* @author Michal Kliment
* @param type $member_id
* @return type
*/
public function get_all_devices_by_member($member_id = NULL)
{
$member_clause = '';
if ($member_id)
$member_clause = 'AND u.member_id = '.intval($member_id);
return $this->db->query("
SELECT
d.id,
IF(d.name <> '', d.name, IFNULL(t.translated_term, et.value)) AS name
FROM devices d
JOIN users u ON d.user_id = u.id $member_clause
JOIN enum_types et ON d.type = et.id
LEFT JOIN translations t ON t.original_term = et.value AND lang = ?
ORDER BY name
", array(Config::get('lang')));
}
}
freenetis/branches/testing/application/models/iface.php
{
return $this->db->where('mac', $mac)->count_records('ifaces');
}
/**
* Function gets interfaces of given device, used for deleting.
*
* @param integer $device_id
* @return Mysql_Result
*/
public function get_ifaces_of_device($device_id)
{
return $this->db->query("
SELECT *
FROM ifaces
WHERE device_id = ?
", $device_id);
}
/**
* Returns all interfaces of device
......
}
/**
* Gets ifaces of device
*
* @param integer $device_id
* @return Mysql_Result
*/
public function get_ifaces_by_device($device_id)
{
return $this->select(array
(
'devices.name as device_name', 'segments.name as segment_name',
'segments.id as segment_id', 'ifaces.*'
))->join('devices', 'devices.id', 'ifaces.device_id')
->join('segments', 'segments.id', 'ifaces.segment_id', 'LEFT')
->orderby('id', 'ASC')
->where('device_id', $device_id)
->find_all();
}
/**
* Gets array of ifaces with device for dripdown
*
* @author Ondřej fibich
freenetis/branches/testing/application/models/vlan_iface.php
* @param integer $device_id
* @return Mysql_Result
*/
public function get_all_vlan_ifaces_by_device_id ($device_id)
public function get_all_vlan_ifaces_by_device_id ($device_id, $order_by = 'tag_802_1q')
{
if (!$this->has_column($order_by))
$order_by = 'tag_802_1q';
return $this->db->query("
SELECT vi.*, vi.id AS vlan_iface_id, vi.name AS vlan_iface_name,
v.id AS vlan_id, v.name AS vlan_name,
freenetis/branches/testing/application/models/vlan.php
*/
class Vlan_Model extends ORM
{
/**
* Const for default VLAN
*/
const DEFAULT_VLAN = 1;
protected $has_many = array('vlan_ifaces');
protected $has_and_belongs_to_many = array('ports');
/**
* Returns default VLAN
*
* @author Michal Kliment
* @return Port_Model object
*/
public function get_default_vlan()
{
return $this
->where('tag_802_1q', self::DEFAULT_VLAN)
->find();
}
/**
* Get count of vlans
*
* @return integer
......
ORDER BY INET_ATON(IFNULL(d.ip_address, IFNULL(ip1.ip_address,ip2.ip_address)))
", array($vlan_id, $vlan_id, __('Port').' ', $vlan_id));
}
/**
* Returns all VLAN ports belongs to port
*
* @author Michal Kliment
* @param type $port_id
* @return type
*/
public function get_all_vlans_by_port ($port_id)
{
return $this->db->query("
SELECT v.*, pv.tagged
FROM vlans v
JOIN ports_vlans pv ON pv.vlan_id = v.id
JOIN ports p ON pv.port_id = p.id
WHERE p.id = ?
", $port_id);
}
}
freenetis/branches/testing/application/models/member.php
/**
* Returns all members to dropdown
*
* @todo I think this format is better than default select list
* @author Michal Kliment
* @return Mysql_Result object
*/
public function get_all_members_to_dropdown ()
{
return $this->db->query("
SELECT m.id, CONCAT(u.surname,' ',u.name, ' (ID ',m.id,')') AS name
SELECT m.id,
CONCAT(IF(
CONCAT(u.name,' ',u.surname) = m.name,
CONCAT(u.surname,' ',u.name),
m.name
), ' (ID ',m.id,')') AS name
FROM members m
JOIN users u ON u.member_id = m.id AND u.type = ?
ORDER BY name
freenetis/branches/testing/application/models/port.php
* @property integer $port_nr
* @property string $name
* @property ORM_Iterator $vlans
* @property integer $mode
* @property integer $port_vlan_id
* @property Vlan_Model $port_vlan
*/
class Port_Model extends ORM
{
protected $belongs_to = array('segment', 'device');
/**
* Const for mode access
*/
const MODE_ACCESS = 1;
/**
* Const for mode trunk
*/
const MODE_TRUNK = 2;
/**
* Const for mode hybrid
*/
const MODE_HYBRID = 3;
/**
* Human format for modes
* @var array
*/
private static $modes = array
(
self::MODE_ACCESS => 'Access',
self::MODE_TRUNK => 'Trunk',
self::MODE_HYBRID => 'Hybrid'
);
protected $belongs_to = array('segment', 'device', 'port_vlan' => 'vlan');
protected $has_and_belongs_to_many = array('vlans');
/**
* Return human format for given const of mode
*
* @author Michal Kliment
* @param type $mode
* @return boolean
*/
public static function get_mode($mode)
{
if (isset(self::$modes[$mode]))
return __(self::$modes[$mode]);
else
return FALSE;
}
/**
* Return human format for modes
*
* @author Michal Kliment
* @return type
*/
public static function get_modes()
{
return array_map('__', self::$modes);
}
/**
* Gets count of ports of device
......
public function get_ports_of_device($device_id)
{
return $this->db->query("
SELECT ports.id AS port_id, ports.name AS port_name,
devices.name as device_name,ports.segment_id, segments.name as segment_name,
IFNULL(ports_vlans.vlan_count,0) AS vlan_count, ports.id,ports.name,
ports.port_nr
FROM ports
LEFT JOIN devices ON devices.id = ports.device_id
LEFT JOIN segments ON segments.id = ports.segment_id
SELECT
p.id AS port_id, p.name AS port_name,
d.name as device_name, p.segment_id, s.name as segment_name,
IFNULL(pv.vlan_count,0) AS vlan_count, p.id, p.name,
p.port_nr, s.bitrate, p.mode
FROM ports p
LEFT JOIN devices d ON d.id = p.device_id
LEFT JOIN segments s ON s.id = p.segment_id
LEFT JOIN (
SELECT COUNT(*) as vlan_count,port_id
FROM ports_vlans
GROUP BY port_id
) ports_vlans ON ports_vlans.port_id=ports.id
WHERE device_id=?
) pv ON pv.port_id = p.id
WHERE device_id = ?
ORDER BY port_nr ASC
", $device_id);
}
freenetis/branches/testing/application/controllers/ifaces.php
$view->content = new View('ifaces/show');
$view->content->iface = $iface;
$view->content->headline = $headline;
$view->content->table_ip_addresses = $grid_ip_addresses;
$view->content->table_vlan_ifaces = $grid_vlan_ifaces;
$view->render(TRUE);
} // end of show
......
*/
public function add($device_id = null)
{
$form = new Forge('ifaces/add/' . $device_id);
$form = new Forge();
$form->group('Basic data');
......
if($form->validate())
{
$form_data = $form->as_array();
$iface = new Iface_Model();
$iface->name = $form_data['iname'];
$iface->type = $form_data['itype'];
$iface->device_id = $form_data['device_id'];
$iface->segment_id = $form_data['segment_id'];
$iface->mac = $form_data['mac'];
$iface->comment = $form_data['comment'];
$iface_saved = $iface->save();
if ($iface->type == Iface_Model::TYPE_WIRELESS)
try
{
$iface->wireless->wmode = $form_data['wmode'];
$iface->wireless->antenna = $form_data['antenna'];
$iface->transaction_start();
$iface->wireless->iface_id = $iface->id;
$iface->wireless->save();
if ($iface->wireless->wmode = Wireless_iface_Model::MODE_AP)
$iface->name = $form_data['iname'];
$iface->type = $form_data['itype'];
$iface->device_id = $form_data['device_id'];
$iface->segment_id = $form_data['segment_id'];
$iface->mac = $form_data['mac'];
$iface->comment = $form_data['comment'];
$iface->save_throwable();
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$iface->segment->wireless->ssid = $form_data['ssid'];
$iface->segment->wireless->norm = $form_data['norm'];
$iface->segment->wireless->frequence = $form_data['frequence'];
$iface->segment->wireless->channel = $form_data['channel'];
$iface->segment->wireless->channel_width = $form_data['channel_width'];
$iface->segment->wireless->polarization = $form_data['polarization'];
$iface->segment->wireless->segment_id = $iface->segment->id;
$iface->segment->wireless->save();
$iface->wireless->wmode = $form_data['wmode'];
$iface->wireless->antenna = $form_data['antenna'];
$iface->wireless->iface_id = $iface->id;
$iface->wireless->save_throwable();
if ($iface->wireless->wmode = Wireless_iface_Model::MODE_AP)
{
$iface->segment->wireless->ssid = $form_data['ssid'];
$iface->segment->wireless->norm = $form_data['norm'];
$iface->segment->wireless->frequence = $form_data['frequence'];
$iface->segment->wireless->channel = $form_data['channel'];
$iface->segment->wireless->channel_width = $form_data['channel_width'];
$iface->segment->wireless->polarization = $form_data['polarization'];
$iface->segment->wireless->segment_id = $iface->segment->id;
$iface->segment->wireless->save_throwable();
}
}
$iface->transaction_commit();
status::success('Interface has been successfully saved.');
$this->redirect('show', $iface->id);
}
unset($form_data);
if ($iface_saved)
catch (Exception $e)
{
status::success('Interface has been successfully saved.');
if (Path::instance()->previous()->uri()->current(0,1) == 'devices')
url::redirect(url_lang::base() . 'devices/show_iface/' . $iface->id);
else
url::redirect(url_lang::base() . 'ifaces/show/' . $iface->id);
$iface->transaction_rollback();
status::error('Error - Cannot add interface.');
$this->redirect('show_all');
}
}
// device is set
if ($device_id)
else
{
$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
// device is set
if ($device_id)
{
$breadcrumbs = breadcrumbs::add()
->link(
'members/show_all',
'Members',
$this->acl_check_view('Members_Controller','members')
)
)
->link(
'users/show_by_member/'.$device->user->member_id,
"Users",
$this->acl_check_view(
'Users_Controller',
'users',$device->user->member_id
->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/'.$device->user_id,
$device->user->name.' '.$device->user->surname.' ('.$device->user->login.')',
$this->acl_check_view(
'Users_Controller',
'users',
$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(
'devices/show_by_user/'.$device->user_id,
'Devices',
$this->acl_check_view(
'Devices_Controller',
'devices',
$device->user->member_id
->link(
'users/show/'.$device->user_id,
$device->user->name.' '.$device->user->surname.' ('.$device->user->login.')',
$this->acl_check_view(
'Users_Controller',
'users',
$device->user->member_id
)
)
)
->link(
'devices/show/'.$device_id,
$device->name,
$this->acl_check_view(
'Devices_Controller',
'devices',
$device->user->member_id
->link(
'devices/show_by_user/'.$device->user_id,
'Devices',
$this->acl_check_view(
'Devices_Controller',
'devices',
$device->user->member_id
)
)
)
->text('Add new interface')
->html();
->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('Devices_Controller','iface')
)
->text('Add new interface')
->html();
}
$headline = __('Add new interface');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = $headline;
$view->render(TRUE);
}
else
{
$breadcrumbs = breadcrumbs::add()
->link(
'ifaces/show_all',
'Interfaces',
$this->acl_check_view('Devices_Controller','iface')
)
->text('Add new interface')
->html();
}
$headline = __('Add new interface');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = $headline;
$view->render(TRUE);
} // end of add
/**
freenetis/branches/testing/application/controllers/transfers.php
*/
public function payment_calculator($account_id = NULL, $text = FALSE)
{
// access control
if (!$this->acl_check_new('Accounts_Controller', 'transfers'))
Controller::error(ACCESS);
// bad parameter
if (!$account_id || !is_numeric($account_id))
Controller::warning(PARAMETER);
......
// account doesn't exist
if (!$account->id)
Controller::error(RECORD);
// access control
if (!$this->acl_check_view('Accounts_Controller', 'transfers', $account->member_id))
Controller::error(ACCESS);
$fee_model = new Fee_Model();
$device_model = new Device_Model();
freenetis/branches/testing/application/controllers/ports.php
{
public $port_nr = NULL;
private $_device_id = NULL;
/**
* Redirect to show all
*/
......
if (!$this->acl_check_view('Devices_Controller', 'port'))
Controller::error(ACCESS);
$query = $port->vlans;
$vlan_model = new Vlan_Model();
$vlans = $vlan_model->get_all_vlans_by_port($port->id);
$grid_vlans = new Grid('ports', null, array
(
'separator' => '',
'use_paginator' => false,
'use_selector' => false
));
$grid_vlans->field('id')
->label('ID')
->class('center');
));
$grid_vlans->field('name')
->label(__('Port name'));
->label(__('VLAN name'));
$grid_vlans->field('tag_802_1q');
$grid_vlans->field('tag_802_1q')
->class('center');
$grid_vlans->field('comment');
$grid_vlans->callback_field('tagged')
->callback('callback::boolean')
->label('Tagged VLAN')
->class('center');
$grid_vlans->datasource( $query );
$actions = $grid_vlans->grouped_action_field();
if ($this->acl_check_view('Devices_Controller', 'vlan'))
{
$actions->add_action()
->icon_action('show')
->url('vlans/show')
->class('popup_link');
}
if ($this->acl_check_edit('Devices_Controller', 'vlan'))
{
$actions->add_action()
->icon_action('edit')
->url('vlans/edit')
->class('popup_link');
}
if ($this->acl_check_delete('Devices_Controller', 'vlan'))
{
$actions->add_action()
->icon_action('delete')
->url('vlans/delete')
->class('delete_link popup_link');
}
$grid_vlans->datasource($vlans);
if (url_lang::current(1) != 'ports')
{
......
if (!$this->acl_check_new('Devices_Controller', 'port'))
Controller::error(ACCESS);
$form = new Forge('ports/add/'.$device_id);
$form = new Forge();
$form->group('Basic data');
$form->input('name')
->label(__('Port name').':')
->rules('required|length[3,200]');
$form->input('port_nr')
->label(__('Port number').':')
->rules('valid_numeric')
->rules('required|valid_numeric')
->callback(array($this, 'valid_port_nr'));
$form->input('name')
->label(__('Port name').':')
->rules('length[3,200]');
$member_id = NULL;
if ($device_id)
......
$member_id = $device->user->member_id;
$form->dropdown('device_id')
->label(__('Device name') . ':')
->options(array($device_id => $device->name))
->rules('required');
$this->_device_id = $device->id;
}
else
{
......
$segment_model = new Segment_Model();
$vlan_model = new Vlan_Model();
$arr_segments = array
(
NULL => '----- '.__('select segment').' -----'
......
->options($arr_segments)
->rules('required')
->add_button('segments');
$modes = arr::merge(array
(
NULL => '----- '.__('Select mode').' -----'
), Port_Model::get_modes());
$form->dropdown('mode')
->rules('required')
->options($modes)
->selected(Port_Model::MODE_ACCESS)
->callback(array($this, 'valid_mode'));
$default_vlan = $vlan_model->get_default_vlan();
$default_vlans = arr::merge(array
(
NULL => '----- '.__('Select port VLAN').' -----'
), $arr_vlans);
$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'))
->add_button('vlans');
$form->dropdown('vlan_id[]')
->label(__('Vlan name'))
$form->dropdown('tagged_vlan_id[]')
->label(__('Tagged VLANs'))
->options($arr_vlans)
->multiple('multiple')
->size(30)
->add_button('vlans', '{tag_802_1q} - {name}');
->add_button('vlans');
$form->dropdown('untagged_vlan_id[]')
->label(__('Untagged VLANs'))
->options($arr_vlans)
->selected($default_vlan->id)
->callback(array($this, 'valid_vlans'))
->multiple('multiple')
->size(30)
->add_button('vlans');
$form->submit('Save');
......
if ($form->validate())
{
$form_data = $form->as_array();
$port = new Port_Model();
try
{
$port->transaction_start();
$port->port_nr = $form_data['port_nr'];
$port->name = $form_data['name'];
$arr_vlan_id = array();
if ($device_id)
$port->device_id = $device_id;
else
$port->device_id = $form_data['device_id'];
if (isset($_POST['vlan_id']))
$arr_vlan_id = $_POST['vlan_id'];
$port->segment_id = $form_data['segment_id'];
$port = new Port_Model();
$port->name = $form_data['name'];
$port->port_nr = $form_data['port_nr'];
$port->device_id = $form_data['device_id'];
$port->segment_id = $form_data['segment_id'];
$saved = $port->save();
if ($saved)
{
$port->mode = $form_data['mode'];
$port->port_vlan_id = $form_data['port_vlan_id'];
$port->save_throwable();
$vlans = new Ports_vlan_Model();
foreach ($arr_vlan_id as $vlan_id)
foreach ((array) $form_data['tagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->save();
$vlans->tagged = TRUE;
$vlans->save_throwable();
$vlans->clear();
}
}
unset($form_data);
if ($saved)
{
foreach ((array) $form_data['untagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->tagged = FALSE;
$vlans->save_throwable();
$vlans->clear();
}
$port->transaction_commit();
status::success('Port has been successfully saved.');
if ($device_id && $device->id)
url::redirect('devices/show_port/' . $port->id);
if ($device_id)
$this->redirect('devices/show/'.$port->id);
else
url::redirect('ports/show/' . $port->id);
$this->redirect('show', $port->id);
}
catch (Exception $e)
{
$port->transaction_rollback();
status::error('Error - Cannot save port.');
$this->redirect('show_all', $port->id);
}
}
if ($device_id && $device->id)
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->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))
->enable_translation()
->link('users/show_by_member/' . $device->user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->disable_translation()
->link('users/show/' . $device->user->id,
$device->user->name . ' ' . $device->user->surname . ' (' . $device->user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->enable_translation()
->link('devices/show_by_user/' . $device->user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $device->user->member_id))
->disable_translation()
->link('devices/show/' . $device->id . '#device_ports_link',
$device->name,
$this->acl_check_edit('Devices_Controller', 'devices', $device->user->member_id))
->enable_translation();
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('ports/show_all', 'Ports',
$this->acl_check_view('Devices_Controller', 'port'));
if ($device_id && $device->id)
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('members/show_all', 'Members',
$this->acl_check_view('Members_Controller', 'members'))
->disable_translation()
->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))
->enable_translation()
->link('users/show_by_member/' . $device->user->member_id, 'Users',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->disable_translation()
->link('users/show/' . $device->user->id,
$device->user->name . ' ' . $device->user->surname . ' (' . $device->user->login . ')',
$this->acl_check_view('Users_Controller', 'users', $device->user->member_id))
->enable_translation()
->link('devices/show_by_user/' . $device->user->id, 'Devices',
$this->acl_check_view('Devices_Controller', 'devices', $device->user->member_id))
->disable_translation()
->link('devices/show/' . $device->id . '#device_ports_link',
$device->name,
$this->acl_check_edit('Devices_Controller', 'devices', $device->user->member_id))
->enable_translation();
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('ports/show_all', 'Ports',
$this->acl_check_view('Devices_Controller', 'port'));
}
$breadcrumbs->text('Add new port');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = __('Add new port');
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = __('Add new port');
$view->render(TRUE);
}
$breadcrumbs->text('Add new port');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = __('Add new port');
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = __('Add new port');
$view->render(TRUE);
} // end of add
/**
* Function edits port.
*
* @param integer $port_id
*/
public function edit($port_id = null)
{
$ssDevice_id = $this->session->get('ssDevice_id');
public function edit($port_id = NULL)
{
// bad parameter
if (!$port_id || !is_numeric($port_id))
{
Controller::warning(PARAMETER);
}
Controller::warning (PARAMETER);
$port = new Port_Model($port_id);
if (!$port || !$port->id)
{
Controller::warning(RECORD);
}
// record doesn't exist
if (!$port->id)
Controller::error (RECORD);
if (!$this->acl_check_edit(
'Devices_Controller', 'port', $port->device->user->member_id
))
{
// access control
if (!$this->acl_check_new('Devices_Controller', 'port'))
Controller::error(ACCESS);
}
$this->port_nr = $port->port_nr;
$form = new Forge();
$form = new Forge('ports/edit/'.$port_id);
$form->group('Basic data');
$form->input('port_nr')
->value($port->port_nr)
->label(__('Port number').':')
->rules('required|valid_numeric')
->callback(array($this, 'valid_port_nr'));
$form->input('name')
->value($port->name)
->label(__('Port name').':')
->rules('required|length[3,200]')
->value($port->name);
->rules('length[3,200]');
$form->input('port_nr')
->label(__('Port number').':')
->rules('valid_numeric')
->value($port->port_nr)
->callback(array($this, 'valid_port_nr'));
$member_id = NULL;
$device_model = new Device_Model();
$arr_devices = array
(
NULL => '----- '.__('select device').' -----'
) + $device_model->select_list('id', 'name');
$form->dropdown('device_id')
->label(__('Device name'))
->options(array
(
$port->device_id => $port->device->name
))
->options($arr_devices)
->selected($port->device_id)
->rules('required');
if (!$this->acl_check_new('Devices_Controller','port',$member_id))
Controller::Error(ACCESS);
$segment_model = new Segment_Model();
$arr_segments = $segment_model->get_all_segments_to_port_dropdown();
$concat = "CONCAT(COALESCE(tag_802_1q, ''), ' - ', COALESCE(name, ''))";
$arr_vlans = ORM::factory('vlan')->select_list('id', $concat);
$arr_vlan_id_sel = array();
foreach ($port->vlans as $vlan)
$arr_vlan_id_sel[] = $vlan->id;
$vlan_model = new Vlan_Model();
$arr_segments = array
(
NULL => '----- '.__('select segment').' -----'
) + $segment_model->get_all_segments_to_port_dropdown();
$form->dropdown('segment_id')
->label(__('Segment name'))
->options($arr_segments)
->selected($port->segment_id)
->rules('required')
->selected($port->segment_id)
->add_button('segments');
$modes = arr::merge(array
(
NULL => '----- '.__('Select mode').' -----'
), Port_Model::get_modes());
$form->dropdown('mode')
->rules('required')
->options($modes)
->selected($port->mode)
->callback(array($this, 'valid_mode'));
$vlan_model = new Vlan_Model();
$arr_vlans = $vlan_model->select_list();
$default_vlans = arr::merge(array
(
NULL => '----- '.__('Select port VLAN').' -----'
), $arr_vlans);
$form->dropdown('port_vlan_id')
->options($default_vlans)
->selected($port->port_vlan_id)
->rules('required')
->label('Port VLAN')
->help('port_vlan')
->callback(array($this, 'valid_port_vlan'))
->add_button('vlans');
$vlans = $vlan_model->get_all_vlans_by_port($port->id);
$tagged_vlans = $untagged_vlans = array();
foreach ($vlans as $vlan)
{
if ($vlan->tagged)
$tagged_vlans[] = $vlan->id;
else
$untagged_vlans[] = $vlan->id;
}
$form->dropdown('vlan_id[]')
->label(__('Vlan name'))
$form->dropdown('tagged_vlan_id[]')
->label(__('Tagged VLANs'))
->options($arr_vlans)
->selected($tagged_vlans)
->multiple('multiple')
->size(30)
->selected($arr_vlan_id_sel)
->add_button('vlans', '{tag_802_1q} - {name}');
->add_button('vlans');
$form->dropdown('untagged_vlan_id[]')
->label(__('Untagged VLANs'))
->options($arr_vlans)
->selected($untagged_vlans)
->callback(array($this, 'valid_vlans'))
->multiple('multiple')
->size(30)
->add_button('vlans');
$form->submit('Update');
$form->submit('Save');
special::required_forge_style($form, ' *', 'required');
if ($form->validate())
{
$form_data = $form->as_array();
$arr_vlan_id = isset($_POST['vlan_id']) ? $_POST['vlan_id'] : array();
$port = new Port_Model($port_id);
$port->name = $form_data['name'];
$port->port_nr = $form_data['port_nr'];
$port->device_id = $form_data['device_id'];
$port->segment_id = $form_data['segment_id'];
$ports_vlans_model = new Ports_vlan_Model();
$ports_vlans = $ports_vlans_model->where('port_id', $port_id)->find_all();
foreach ($ports_vlans as $vlan)
try
{
$vlan->delete();
}
$port->transaction_start();
$port->port_nr = $form_data['port_nr'];
$port->name = $form_data['name'];
$port->device_id = $form_data['device_id'];
$port->segment_id = $form_data['segment_id'];
$port->mode = $form_data['mode'];
$port->port_vlan_id = $form_data['port_vlan_id'];
$port->save_throwable();
$ports_vlans_model = new Ports_vlan_Model();
$ports_vlans = $ports_vlans_model
->where('port_id', $port_id)
->find_all();
$saved = $port->save();
if ($saved)
{
foreach ($ports_vlans as $vlan)
$vlan->delete_throwable();
$vlans = new Ports_vlan_Model();
foreach ($arr_vlan_id as $vlan_id)
foreach ((array) $form_data['tagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->save();
$vlans->tagged = TRUE;
$vlans->save_throwable();
$vlans->clear();
}
}
unset($form_data);
if ($saved)
{
foreach ((array) $form_data['untagged_vlan_id'] as $vlan_id)
{
if ($vlan_id == 0)
break;
$vlans->vlan_id = $vlan_id;
$vlans->port_id = $port->id;
$vlans->tagged = FALSE;
$vlans->save_throwable();
$vlans->clear();
}
$port->transaction_commit();
status::success('Port has been successfully updated.');
if (Path::instance()->previous()->uri()->current(0,1) == 'devices')
url::redirect('devices/show_port/' . $port->id);
else
url::redirect('ports/show/' . $port->id);
exit;
$this->redirect('ports/show/'.$port->id);
}
catch (Exception $e)
{
$port->transaction_rollback();
status::error('Error - Cannot update port.');
$this->redirect('show_all');
}
}
if (url::slice(url_lang::uri(Path::instance()->previous()->current()), 0,1) == 'devices')
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
......
$this->acl_check_edit('Devices_Controller', 'devices', $port->device->user->member_id))
->link('devices/show_port/' . $port->id, $port->name,
$this->acl_check_view('Devices_Controller', 'port' ,$port->device->user->member_id))
->enable_translation();
->enable_translation()
->text('Edit');
$title = __('Edit port');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = $title;
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = $title;
$view->render(TRUE);
}
else
{
// breadcrumbs navigation
$breadcrumbs = breadcrumbs::add()
->link('ports/show_all', 'Ports',
$this->acl_check_view('Devices_Controller', 'port'))
->link('ports/show/' . $port->id, $port->name,
$this->acl_check_view('Devices_Controller', 'port', $port->device->user->member_id));
}
$breadcrumbs->text('Edit');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs->html();
$view->title = __('Edit port').' - '.$port->name;
$view->content = new View('form');
$view->content->form = $form->html();
$view->content->headline = __('Edit port').' - '.$port->name;
$view->render(TRUE);
} // end of edit
/**
* Function deletes port.
* Deletes port
*
* @param integer $port_id
* @author Michal Kliment
* @param type $port_id
*/
public function delete($port_id = null)
{
......
Controller::error(ACCESS);
}
// removing relation from pivot table using ORM would be better,
// but I could not found useful documentation
// so I have written own query
$port->delete_from_pivot_table($port_id);
if ($port->delete())
try
{
$port->transaction_start();
$port->delete_throwable();
$port->transaction_commit();
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff