Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1610

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

Upravy:

- pridava/editace rozhrani prepracovana do stejneho stylu jako u pridavani zarizeni
- pridani pripojeno k u zobrazeni uzivatelovych zarizeni (#256)
- moznost pridat rozhrani k roaming lince (odkaz umistnen v zobrazeni roaming linky)
- uprava zobrazeni linku a rozhrani

Opravy:

- upravena logika prace s linkou pri jeji pridavani a pouziti v relaci s rozhranimi
- oprava zobrazeni zarizeni uzivatele - nezobrazovali se spravně IP adresy

Zobrazit rozdíly:

freenetis/branches/testing/application/i18n/cs_CZ/texts.php
'answer' => 'Odpověd',
'answer to this message' => 'Odpovědet na tuto zprávu',
'any' => 'Jakékoliv',
'append interface to link' => 'Přidat k linkce rozhraní',
'applicant' => 'Čekatel na členství',
'applicant for membership' => 'Zájemce o členství',
'application password' => 'Aplikační heslo',
......
'chairman and agent' => 'Předseda a jednatel',
'change' => 'Změnit',
'change application password' => 'Změnit aplikační heslo',
'change connected to (link) settings?' => 'Změnit nastavení připojení k (linky)?',
'change directory permissions:' => 'Změnte práva složky:',
'change language' => 'Změnit jazyk',
'change member limit' => 'Změnit limit člena',
......
'internal interfaces' => 'Vnitřní rozhraní',
'inteligent select' => 'Inteligentní výběr',
'interface detail' => 'Detail rozhraní',
'interface has been successfully appended to link' => 'Rozhraní bylo úspěšně přiřazeno k lince',
'interface has been successfully saved' => 'Rozhraní bylo úspěšně uloženo.',
'interface has been successfully updated' => 'Rozhraní bylo úspěšně upraveno.',
'interface has been successfully deleted' => 'Rozhraní bylo úspěšně smazáno.',
......
'text for self cancel anchor' => 'Text pro odkaz na samozrušení přesměrování',
'thank you for your error report' => 'Děkujeme Vám za hlášení chyby',
'thank you for your registration' => 'Děkujeme Vám za vaši registraci',
'the connected to information in the link section contains only one of these devices' => 'Informace o připojení k v sekci linka obsahují pouze jedno z těchno zařízení.',
'the first bank account information' => 'Údaje o prvním bankovním účtu',
'the parsed account is unknown' => 'Parsovaný účet je neznámý',
'the request has been sent to your e-mail' => 'Žádost byla odeslána na Váš e-mail',
......
'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.',
'this approval template already contains this approval type' => 'Tato hlasovací šablona již obsahuje tento hlasovací typ.',
'this interface is connected to multiple devices' => 'Toto rozhraní je připojeno k více zařízením.',
'this information is required' => 'Tento údaj je povinný.',
'this member has already set up this fee type for this interval' => 'Tento člen má již nastaven tento typ poplatku pro tento interval.',
'this member has default system member fee %d %s' => 'Tento člen má výchozí systémový členský příspěvek %d %s.',
freenetis/branches/testing/application/vendors/unit_tester/unit_testing_config.xml
</input>
</values>
</method>
<method name="add_iface_to_link" autogenerate="on">
<attributes>
<attribute name="link_id" default_value="" />
</attributes>
<values>
<input></input>
<input>
<param value="" />
</input>
</values>
</method>
<method name="edit" autogenerate="off">
<attributes>
<attribute name="iface_id" default_value=""/>
......
</input>
</values>
</method>
<method name="valid_link" autogenerate="on">
<attributes>
<attribute name="input" default_value="" />
</attributes>
<values>
<input></input>
<input>
<param value="" />
</input>
</values>
</method>
<method name="valid_mode" autogenerate="off">
<attributes>
<attribute name="input" default_value=""/>
......
<method name="select_list_filtered_device_with_user" autogenerate="on">
<attributes>
<attribute name="filter_sql" default_value="" />
<attribute name="json" default_value="TRUE" />
</attributes>
<values>
<input></input>
<input>
<param value="" />
</input>
<input>
<param value="" />
<param value="TRUE" />
</input>
</values>
</method>
<method name="get_all_devices_of_link" autogenerate="on">
......
</input>
</values>
</method>
<method name="get_all_connected_to_device" autogenerate="on">
<attributes>
<attribute name="device_id" default_value="" />
</attributes>
<values>
<input>
<param value="" />
</input>
</values>
</method>
<method name="get_all_devices_by_member" autogenerate="on">
<attributes>
<attribute name="member_id" default_value="" />
......
<values>
</values>
</method>
<method name="device_connected_to_device" autogenerate="on">
<attributes>
<attribute name="item" default_value="" />
<attribute name="name" default_value="" />
</attributes>
<values>
<input>
<param value="" />
<param value="" />
</input>
</values>
</method>
<method name="email_from_field" autogenerate="off">
<attributes>
<attribute name="item" default_value=""/>
freenetis/branches/testing/application/helpers/callback.php
* @param type $name
*/
public static function connected_to_device ($item, $name)
{
{
if ($item->connected_to_device_id)
{
if ($item->connected_to_devices_count == 1)
{
echo html::anchor(
url_lang::base().'devices/show/'.$item->connected_to_device_id,
'devices/show/'.$item->connected_to_device_id,
$item->connected_to_device_name
);
}
else if (isset($item->link_id))
{
echo html::anchor(
'links/show/'.$item->link_id,
__('More devices'), array
(
'class' => 'more',
'title' => $item->connected_to_devices
)
);
}
else
{
echo "<span class='more' title='".$item->connected_to_devices."'>".__('More devices')."</span>";
echo '<span class="more" title="'.$item->connected_to_devices.'">'.__('More devices').'</span>';
}
}
else
{
if (Iface_Model::type_has_link($item->type))
echo "<span style='color: green'>".__('Not connected')."</span>";
echo '<span style="color: green">'.__('Not connected').'</span>';
else
echo '-';
}
}
/**
* Callback function to print connected device to device
*
* @author Ondřej Fibich
* @param type $item
* @param type $name
*/
public static function device_connected_to_device ($item, $name)
{
$connected = ORM::factory('device')->get_all_connected_to_device($item->id);
if (isset($connected->connected_to_device_id) &&
$connected->connected_to_device_id)
{
if ($connected->connected_to_devices_count == 1)
{
echo html::anchor(
'devices/show/'.$connected->connected_to_device_id,
$connected->connected_to_device_name
);
}
else
{
echo "<span class='more' title='".$connected->connected_to_devices."'>".__('More devices')."</span>";
}
}
else
{
echo "<span style='color: green'>".__('Not connected')."</span>";
}
}
/**
* Callback function to print e-mail From address
*
* @author Michal Kliment
......
$item->ip_address;
if (isset($item->ip_addresses))
{
$title = $item->ip_addresses;
if (isset($item->more_ips) && $item->more_ips)
$class = 'more';
if (count(explode(',', $item->ip_addresses)) > 2)
{
$class = 'more';
}
}
if ((!isset($args[1]) || $args[1]) && $item->ip_address_id)
{
freenetis/branches/testing/application/models/device.php
*/
public function get_devices_of_user(
$user_id, $display_empty = TRUE, $limit_from = 0,
$limit_results = NULL, $order_by = 'ip', $order_by_direction = 'asc')
$limit_results = NULL, $order_by = 'ip_address',
$order_by_direction = 'asc')
{
// order by check
if (!$this->has_column($order_by) && $order_by != 'ip')
// fix ip address
if ($order_by == 'ip_address')
{
$order_by = 'id';
$order_by = 'INET_ATON(ip_address)';
}
// order by direction check
if (strtolower($order_by_direction) != 'desc')
......
$order_by_direction = 'asc';
}
$limit = "";
$limit = '';
if ($limit_results)
$limit = "LIMIT " . intval($limit_from) . ", " . intval($limit_results);
$limit = 'LIMIT ' . intval($limit_from) . ', ' . intval($limit_results);
$display_empty_sql = '';
if (!$display_empty)
{
$display_empty_sql = "AND NOT (
(ISNULL(ip.ip_address) OR LENGTH(ip.ip_address) = 0) AND
(ISNULL(i.mac) OR LENGTH(i.mac) = 0)
(ISNULL(ip.ip_address) OR LENGTH(ip.ip_address) = 0)
)";
}
return $this->db->query("
SELECT d.*, IF(COUNT(d.id)>1,1,0) AS more_ips,
GROUP_CONCAT(ip_address SEPARATOR ', \n') AS ip_addresses,
s.name AS subnet_name, l.name AS link_name
FROM
(
SELECT * FROM
(
SELECT d.id, d.name, d.buy_date, IFNULL(t.translated_term,e.value) AS type,
i.mac, ip.ip_address, ip.id AS ip_address_id,
ip.ip_address AS ip, ip.subnet_id, i.id AS iface_id,
i.name AS iface_name, i.link_id
FROM devices d
LEFT JOIN enum_types e ON d.type = e.id
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
LEFT JOIN ifaces i ON d.id = i.device_id
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
WHERE user_id = ? $display_empty_sql
) AS d
ORDER BY $order_by $order_by_direction
) AS d
LEFT JOIN subnets s ON d.subnet_id = s.id
LEFT JOIN links l ON d.link_id = l.id
SELECT d.*, i.id AS iface_id, i.mac, ip.id AS ip_address_id,
ip.ip_address, s.id AS subnet_id, s.name AS subnet_name,
IFNULL(t.translated_term,e.value) AS type,
GROUP_CONCAT(IF(ip.ip_address IS NULL, '', CONCAT(ip.ip_address, ',\\n')) SEPARATOR '') AS ip_addresses
FROM devices d
LEFT JOIN enum_types e ON d.type = e.id
LEFT JOIN translations t ON e.value LIKE t.original_term AND t.lang = ?
LEFT JOIN ifaces i ON d.id = i.device_id
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id
LEFT JOIN subnets s ON ip.subnet_id = s.id
WHERE user_id = ? $display_empty_sql
GROUP BY d.id
ORDER BY $order_by $order_by_direction
$limit
......
/**
* Select list of user and their devices
*
* @param string $filter_sql Filter query
* @param boolean $json Indicator if JSON is enabled (change structure)
* @return array
*/
public function select_list_filtered_device_with_user($filter_sql = '')
public function select_list_filtered_device_with_user($filter_sql = '', $json = TRUE)
{
$where = '';
if (!empty($filter_sql))
......
}
}
$arr_devices[$device->user_name][] = array('id' => $device->id, 'name' => $name);
if ($json === TRUE)
{
$arr_devices[$device->user_name][] = array('id' => $device->id, 'name' => $name);
}
else
{
$arr_devices[$device->user_name][$device->id] = $name;
}
}
return $arr_devices;
......
}
/**
* Returns all devices of link
*
* @author Michal Kliment
* @param integer $device_id
* @return object
*/
public function get_all_connected_to_device($device_id)
{
return $this->db->query("
SELECT
cd.id AS connected_to_device_id,
cd.name AS connected_to_device_name,
IFNULL(COUNT(DISTINCT cd.id), 0) AS connected_to_devices_count,
GROUP_CONCAT(DISTINCT cd.name SEPARATOR ', \\n') AS connected_to_devices
FROM devices d
JOIN ifaces i ON i.device_id = d.id
JOIN links l ON i.link_id = l.id
JOIN ifaces ci ON ci.link_id = l.id AND ci.id <> i.id AND
(
i.type NOT IN(?, ?) OR
(
i.type IN(?, ?) AND
(
i.wireless_mode = ? AND ci.wireless_mode = ?
) OR i.wireless_mode = ?
)
)
JOIN devices cd ON ci.device_id = cd.id
WHERE d.id = ?
GROUP BY d.id
", array
(
Iface_Model::TYPE_WIRELESS, Iface_Model::TYPE_VIRTUAL_AP,
Iface_Model::TYPE_WIRELESS, Iface_Model::TYPE_VIRTUAL_AP,
Iface_Model::WIRELESS_MODE_CLIENT,
Iface_Model::WIRELESS_MODE_AP,
Iface_Model::WIRELESS_MODE_AP,
$device_id
))->current();
}
/**
* Returns all devices of member
*
* @author Michal Kliment
freenetis/branches/testing/application/models/iface.php
$ifaces = $this->db->query("
SELECT i.id, COALESCE(d.name, '') AS device_name,
CONCAT(u.name, ' ', u.surname, ' - ', u.login) AS user_name,
CONCAT(u.surname, ' ', u.name, ' - ', u.login) AS user_name,
COALESCE(i.name, '') AS name,
COALESCE(CONCAT(' (', i.mac, ')'), '') AS mac
COALESCE(i.mac, '') AS mac
FROM ifaces i
LEFT JOIN devices d ON d.id = i.device_id
JOIN users u ON u.id = d.user_id
......
foreach ($ifaces as $iface)
{
$result[$iface->user_name . ' - ' . $iface->device_name][$iface->id] = $iface->name . $iface->mac;
$name = $iface->name . (!empty($iface->mac) ? ' (' . $iface->mac . ')' : '');
$result[$iface->user_name . ' - ' . $iface->device_name][$iface->id] = $name;
}
return $result;
freenetis/branches/testing/application/models/link.php
JOIN users u ON d.user_id = u.id
JOIN members m ON u.member_id = m.id
WHERE i.link_id = ?
ORDER BY i.wireless_mode
ORDER BY i.wireless_mode DESC, i.name ASC
", $link_id);
}
freenetis/branches/testing/application/controllers/ifaces.php
$this->device_id = $device_id;
$this->iface_type = $type;
$filter_form = Devices_Controller::device_filter_form($device->user_id);
$form = new Forge('ifaces/add/' . $device_id . '/' . $type);
$base_form = $form->group('Basic data');
$form->hidden('itype')
->value($type);
->value($type);
$base_form->input('name')
->label('Interface name')
......
$devices = array
(
NULL => '----- '.__('Select device').' -----'
) + ORM::factory('device')->select_list_device_with_user();
) + $device->select_list_filtered_device_with_user($filter_form->as_sql(), FALSE);
$ifaces = array
(
......
->in('type', Iface_Model::get_can_connect_to($type))
->select_list('id', $concat);
}
$links = array
(
NULL => '----- '.__('Select link').' -----'
) + ORM::factory('link')->select_list_by_iface_type($type);
$c_form = $form->group('Link');
$form->hidden('device_filter');
$medium = Link_Model::MEDIUM_CABLE;
$bitrate = '100M';
$wnorm = null;
if ($type == Iface_Model::TYPE_WIRELESS)
{
$medium = Link_Model::MEDIUM_AIR;
$bitrate = Link_Model::get_wireless_max_bitrate(Link_Model::NORM_802_11_G) . 'M';
$wnorm = Link_Model::NORM_802_11_G;
}
$form->hidden('_device_name')->value($device->name);
$form->hidden('link_id');
$form->hidden('link_name');
$form->hidden('link_comment');
$form->hidden('medium')->value($medium);
$form->hidden('bitrate')->value($bitrate);
$form->hidden('duplex')->value(0);
$form->hidden('wireless_ssid');
$form->hidden('wireless_norm')->value($wnorm);
$form->hidden('wireless_frequency');
$form->hidden('wireless_channel');
$form->hidden('wireless_channel_width');
$form->hidden('wireless_polarization');
$c_form->dropdown('connected_to')
->style('width: 600px')
->style('width: 550px')
->options($devices)
->add_button('devices', 'add_simple', $device->user_id);
$c_form->dropdown('connected_to_interface')
->style('width: 600px')
->style('width: 550px')
->options($ifaces)
->callback(array($this, 'valid_connect_to_iface'))
->add_button('ifaces');
$c_form->dropdown('link_id')
->label('Link')
->options($links)
->callback(array($this, 'valid_link'))
->style('width: 600px')
->add_button('links', 'add', $type);
}
$form->submit('Save');
// form is validate
if($form->validate())
{
{
$form_data = $form->as_array();
$iface = new Iface_Model();
......
$iface->comment = $form_data['comment'];
if (!$add_button && Iface_Model::type_has_link($iface->type))
{
$link = new Link_Model($form_data['link_id']);
if ($link && $link->id)
{// connected iface
$im_connect_to = new Iface_Model($form_data['connected_to_interface']);
// save link
if ($im_connect_to && $im_connect_to->id)
{
$iface->link_id = $link->id;
// connected to
$iface_to = new Iface_Model($form_data['connected_to_interface']);
if ($iface_to && $iface_to->id &&
$iface_to->link_id != $link->id)
$roaming = new Link_Model();
$link_id = $_POST['link_id'];
$roaming_id = $roaming->get_roaming();
$roaming = $roaming->find($roaming_id);
$name = $_POST['link_name'];
$medium = $_POST['medium'];
// don not connect to roaming
if ($link_id == $roaming_id)
{
// assing link if not assinged other
if (!$iface_to->link_id)
$link_id = NULL;
// fix name
if (trim($name) == trim($roaming->name))
{
$iface_to->link_id = $link->id;
$iface_to->save_throwable();
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$name = __('air') . ' ';
}
else
{
$name = __('cable') . ' ';
}
if ($im_connect_to->type == Iface_Model::TYPE_WIRELESS &&
$im_connect_to->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$name .= $im_connect_to->device->name;
$name .= ' - ' . $device->name;
}
else
{
$name .= $device->name . ' - ';
$name .= $im_connect_to->device->name;
}
// fix medium
if ($medium == Link_Model::MEDIUM_ROAMING)
{
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$medium = Link_Model::MEDIUM_AIR;
}
else
{
$medium = Link_Model::MEDIUM_CABLE;
}
}
}
else
}
$lm = new Link_Model($link_id);
$lm->name = htmlspecialchars($name);
$lm->medium = intval($medium);
$lm->comment = htmlspecialchars($_POST['link_comment']);
$lm->bitrate = network::str2bytes($_POST['bitrate']);
$lm->duplex = ($_POST['duplex'] == 1);
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid']);
$lm->wireless_norm = intval($_POST['wireless_norm']);
$lm->wireless_frequency = intval($_POST['wireless_frequency']);
$lm->wireless_channel = intval($_POST['wireless_channel']);
$lm->wireless_channel_width = intval($_POST['wireless_channel_width']);
$lm->wireless_polarization = intval($_POST['wireless_polarization']);
}
$lm->save_throwable();
// restrict count of connected devices to link
$max = Link_Model::get_max_ifaces_count($iface->type);
if ($lm->id != $roaming_id &&
$max <= 2) // delete connected (port, eth)
{
foreach ($lm->ifaces as $i_del)
{
throw new Exception(
'Invalid connect to interface - ' .
'already has different link'
);
$i_del->link_id = null;
$i_del->save_throwable();
}
}
$iface->link_id = $lm->id;
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
}
else
{
$iface->link_id = null;
}
}
else
{
$iface->link_id = null;
}
if (Iface_Model::type_has_mac_address($iface->type))
{
......
}
}
// speed units
$arr_unit = array
(
'K' => 'kbps',
'M' => 'Mbps',
'G' => 'Gbps',
'T' => 'Tbps'
);
// ethernet mediums
$eth_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_ETHERNET);
// wireless mediums
$wl_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_WIRELESS);
// port mediums
$port_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_PORT);
// wireless norms
$arr_wireless_norms = Link_Model::get_wireless_norms();
// wireless polarizations
$arr_wireless_polarizations = Link_Model::get_wireless_polarizations();
$headline = __('Add new interface') . ' (' . Iface_Model::get_type($type) . ')';
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('form');
$view->content = new View('ifaces/add');
$view->content->form = $form->html();
$view->content->headline = $headline;
$view->content->filter = $filter_form;
$view->content->norms = $arr_wireless_norms;
$view->content->polarizations = $arr_wireless_polarizations;
$view->content->bit_units = $arr_unit;
$view->content->eth_mediums = $eth_mediums;
$view->content->wl_mediums = $wl_mediums;
$view->content->port_mediums = $port_mediums;
$view->render(TRUE);
}
else // redirect after setting of device and type
......
}
}
} // end of add
/**
* Adds iface to a given link
*
* @author Ondřej Fibich
* @param integer $link_id
*/
public function add_iface_to_link($link_id = NULL)
{
if (!intval($link_id))
{
self::warning(PARAMETER);
}
$link = new Link_Model($link_id);
$iface = new Iface_Model();
if (!$link || !$link->id)
{
self::error(RECORD);
}
if (!$this->acl_check_edit('Devices_Controller', 'iface'))
{
self::error(ACCESS);
}
$form = new Forge();
$form->dropdown('iface_id')
->label('Interface')
->options($iface->select_list_grouped_by_device())
->rules('required')
->style('width:400px');
$form->submit('Add');
if ($form->validate())
{
$form_data = $form->as_array();
$iface->find($form_data['iface_id']);
if ($iface->id)
{
$iface->link_id = $link->id;
$iface->save();
status::success('Interface has been successfully appended to link.');
$this->redirect('/links/show/', $link->id);
}
}
$headline = __('Append interface to link');
$breadcrumbs = breadcrumbs::add()
->link('links/show_all', 'Links',
$this->acl_check_view('Devices_Controller', 'segment'))
->link('links/show/' . $link->id, $link->name . ' (' .
Link_Model::get_medium_type($link->medium) . ')',
$this->acl_check_view('Devices_Controller', 'segment'))
->disable_translation()
->text($headline);
$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);
}
/**
* Function edits interface.
......
if (empty($type))
{
$type = $iface->type;
// some wrong added ifaces from the past may have type set to zero
}
// iface type doesn't exist
if (!$iface->get_type($type))
{
Controller::error(RECORD);
// some wrong added ifaces from the past may have type set to zero
if ($type == 0)
{
$type = Iface_Model::TYPE_WIRELESS;
}
else
{
Controller::error(RECORD);
}
}
// some wrong added ifaces from the past may have type set to zero
$this->iface_type = $type;
$filter_form = Devices_Controller::device_filter_form();
$form = new Forge();
......
->select_list('id', $concat);
}
$c_form = $form->group('Link');
$c_form = $form->group(
__('Link') . '&nbsp;&nbsp;&nbsp;' . form::checkbox('change_link', 1) .
'&nbsp;&nbsp;<span style="color: black">' .
__('Change connected to (link) settings?') .
'</span>'
);
$form->hidden('device_filter');
$form->hidden('_device_name')->value($iface->device->name);
$form->hidden('link_id')->value($iface->link_id);
$form->hidden('link_name')->value($iface->link->name);
$form->hidden('link_comment')->value($iface->link->comment);
$form->hidden('medium')->value($iface->link->medium);
$form->hidden('bitrate')->value($iface->link->bitrate);
$form->hidden('duplex')->value($iface->link->duplex);
$form->hidden('wireless_ssid')->value($iface->link->wireless_ssid);
$form->hidden('wireless_norm')->value($iface->link->wireless_norm);
$form->hidden('wireless_frequency')->value($iface->link->wireless_frequency);
$form->hidden('wireless_channel')->value($iface->link->wireless_channel);
$form->hidden('wireless_channel_width')->value($iface->link->wireless_channel_width);
$form->hidden('wireless_polarization')->value($iface->link->wireless_polarization);
$c_form->dropdown('connected_to')
->style('width: 600px')
->style('width: 550px')
->options($devices)
->selected($connecte_to_iface_device_id)
->add_button('devices', 'add_simple', $iface->device->user_id);
$c_form->dropdown('connected_to_interface')
->style('width: 600px')
->style('width: 550px')
->options($ifaces)
->callback(array($this, 'valid_connect_to_iface'))
->selected($connecte_to_iface_id)
->add_button('ifaces');
$c_form->dropdown('link_id')
->label('Link')
->options($links)
->selected($iface->link_id)
->callback(array($this, 'valid_link'))
->style('width: 600px')
->add_button('links', 'add', $type);
}
$form->submit('Save');
......
$iface->comment = $form_data['comment'];
if (Iface_Model::type_has_link($iface->type))
{
$link = new Link_Model($form_data['link_id']);
{// connected iface
$im_connect_to = new Iface_Model($form_data['connected_to_interface']);
if ($link && $link->id)
// save link
if ($im_connect_to && $im_connect_to->id &&
isset($_POST['change_link']) && $_POST['change_link'])
{
$iface->link_id = $link->id;
$roaming = new Link_Model();
$link_id = $_POST['link_id'];
$roaming_id = $roaming->get_roaming();
$roaming = $roaming->find($roaming_id);
$name = $_POST['link_name'];
$medium = $_POST['medium'];
// connected to
$iface_to = new Iface_Model($form_data['connected_to_interface']);
if ($iface_to && $iface_to->id &&
$iface_to->link_id != $link->id)
// don not connect to roaming
if ($link_id == $roaming_id)
{
// assing link if not assinged other
if (!$iface_to->link_id)
$link_id = NULL;
// fix name
if (trim($name) == trim($roaming->name))
{
$iface_to->link_id = $link->id;
$iface_to->save_throwable();
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$name = __('air') . ' ';
}
else
{
$name = __('cable') . ' ';
}
if ($im_connect_to->type == Iface_Model::TYPE_WIRELESS &&
$im_connect_to->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$name .= $im_connect_to->device->name;
$name .= ' - ' . $iface->device->name;
}
else
{
$name .= $iface->device->name . ' - ';
$name .= $im_connect_to->device->name;
}
// fix medium
if ($medium == Link_Model::MEDIUM_ROAMING)
{
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$medium = Link_Model::MEDIUM_AIR;
}
else
{
$medium = Link_Model::MEDIUM_CABLE;
}
}
}
else
}
$lm = new Link_Model($link_id);
$lm->name = htmlspecialchars($name);
$lm->medium = intval($medium);
$lm->comment = htmlspecialchars($_POST['link_comment']);
$lm->bitrate = network::str2bytes($_POST['bitrate']);
$lm->duplex = ($_POST['duplex'] == 1);
if ($iface->type == Iface_Model::TYPE_WIRELESS)
{
$lm->wireless_ssid = htmlspecialchars($form_data['wireless_ssid']);
$lm->wireless_norm = intval($_POST['wireless_norm']);
$lm->wireless_frequency = intval($_POST['wireless_frequency']);
$lm->wireless_channel = intval($_POST['wireless_channel']);
$lm->wireless_channel_width = intval($_POST['wireless_channel_width']);
$lm->wireless_polarization = intval($_POST['wireless_polarization']);
}
$lm->save_throwable();
// restrict count of connected devices to link
$max = Link_Model::get_max_ifaces_count($iface->type);
if ($lm->id != $roaming_id &&
$max <= 2) // delete connected (port, eth)
{
foreach ($lm->ifaces as $i_del)
{
throw new Exception(
'Invalid connect to interface - ' .
'already has different link'
);
$i_del->link_id = null;
$i_del->save_throwable();
}
}
$iface->link_id = $lm->id;
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
}
else
else if (isset($_POST['change_link']) && $_POST['change_link'])
{
$iface_count = $iface->link->ifaces->count();
$iface->link_id = null;
if ($iface_count == 1)
{
$iface->link->delete_throwable();
}
}
}
else
......
)->text('Edit')
->html();
}
// speed units
$arr_unit = array
(
'K' => 'kbps',
'M' => 'Mbps',
'G' => 'Gbps',
'T' => 'Tbps'
);
// ethernet mediums
$eth_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_ETHERNET);
// wireless mediums
$wl_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_WIRELESS);
// port mediums
$port_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_PORT);
// wireless norms
$arr_wireless_norms = Link_Model::get_wireless_norms();
// wireless polarizations
$arr_wireless_polarizations = Link_Model::get_wireless_polarizations();
$headline = __('Edit interface');
$view = new View('main');
$view->breadcrumbs = $breadcrumbs;
$view->title = $headline;
$view->content = new View('form');
$view->content = new View('ifaces/add');
$view->content->form = $form->html();
$view->content->headline = $headline;
$view->content->filter = $filter_form;
$view->content->norms = $arr_wireless_norms;
$view->content->polarizations = $arr_wireless_polarizations;
$view->content->bit_units = $arr_unit;
$view->content->eth_mediums = $eth_mediums;
$view->content->wl_mediums = $wl_mediums;
$view->content->port_mediums = $port_mediums;
// additional infor for AP and reamings
$roaming_id = ORM::factory('link')->get_roaming();
if ($iface->link->id == $roaming_id || (
$iface->type == Iface_Model::TYPE_WIRELESS &&
$iface->wireless_mode == Iface_Model::WIRELESS_MODE_AP
))
{
$view->content->additional_info =
__('This interface is connected to multiple devices.') . ' ' .
__('The connected to information in the link section contains only one of these devices.');
}
$view->render(TRUE);
} // end of edit
......
//remove iface from bridge
$iv = new Ifaces_vlan_Model();
$delete_state = $iv->remove_iface_from_bridge($bridge_iface_id,$iface_id);
$delete_state = $iv->remove_iface_from_bridge($bridge_iface_id, $iface_id);
if ($delete_state)
{
......
}
/**
* Callback function to validate link
*
* @author Michal Kliment
* @param Form_Field $input
*/
public function valid_link($input = NULL)
{
// validators cannot be accessed
if (empty($input) || !is_object($input))
{
self::error(PAGE);
}
if ($input->value)
{
$link = new Link_Model($input->value);
if (!$link || !$link->id)
{
$input->add_error('required', 'Link is required');
}
$mediums = Iface_Model::get_type_has_link_with_medium($this->iface_type);
if (!in_array($link->medium, $mediums))
{
$input->add_error('required', __(
'Link is invalid - its medium has to in ' .
'relation with type of interface.'
));
}
$iface = new Iface_Model($this->iface_id);
$roaming_id = ORM::factory('link')->get_roaming();
if ($link->ifaces->count() >= Link_Model::get_max_ifaces_count($this->iface_type) &&
$link->id != $iface->link_id && $link->id != $roaming_id)
{
$input->add_error('required', __(
'Limit of connected interfaces to link has been reached - ' .
'remove interface from <a href="%s/links/show/%s" target="_blank">link</a> before connecting new one.',
array(Settings::get('suffix').Config::get('lang'), $link->id)
));
}
}
}
/**
* Callback function to validate wireless mode
*
* @author Michal Kliment
freenetis/branches/testing/application/controllers/links.php
'use_selector' => false
));
if ($link->medium == Link_Model::MEDIUM_ROAMING &&
$this->acl_check_edit('Devices_Controller', 'iface'))
{
$grid->add_new_button(
'ifaces/add_iface_to_link/' . $link->id,
__('Append interface to link'),
array('class' => 'popup_link')
);
}
$grid->field('id')
->label('ID');
freenetis/branches/testing/application/controllers/devices.php
if (!in_array($order_by, array_keys($allowed_order_by)))
$order_by = 'id';
if (!in_array(strtolower($order_by_direction), array_keys($allowed_order_by_direction)))
if (strtolower($order_by_direction) != 'desc')
$order_by_direction = 'asc';
// get new selector
......
->selected($order_by_direction);
$order_form->submit('Send');
if ($order_form->validate())
{
$form_data = $order_form->as_array();
url::redirect(
"devices/show_by_user/$user_id/$limit_results/".
$form_data['order_by'].'/'.$form_data['order_by_direction'].
"/$page_word/$page"
);
}
$devices = $device_model->get_devices_of_user($user_id, FALSE);
$devices = $device_model->get_devices_of_user(
$user_id, FALSE, 0, NULL, $order_by, $order_by_direction
);
$base_grid = new Grid('devices', null, array
(
......
$base_grid->link_field('iface_id')
->link('devices/show_iface', 'mac');
$base_grid->link_field('link_id')
->link('links/show', 'link_name')
->label('Link');
$base_grid->callback_field('connected_to_device')
->callback('callback::device_connected_to_device')
->class('center');
$base_grid->callback_field('ip_address')
->callback('callback::ip_address_field');
......
}
}
// filter connect devices form
$filter_form = new Filter_form();
$filter_form->add('subnet')
->type('select')
->values(ORM::factory('subnet')->select_list_by_net())
->css_class('filter_field_subnet');
$filter_form->add('type')
->type('select')
->values(ORM::factory('enum_type')->get_values(Enum_type_model::DEVICE_TYPE_ID));
$filter_form->add('user')
->type('select')
->values(ORM::factory('user')->select_list(
'id', 'CONCAT(surname, \' \', name, \' - \', login)',
'surname'
))->default(Filter_form::OPER_IS, $default_filter_user);
$filter_form->add('device_name')
->callback('json/device_name');
$filter_form->add('town')
->type('select')
->values(array_unique(ORM::factory('town')->select_list('id', 'town')));
$filter_form->add('street')
->type('select')
->values(array_unique(ORM::factory('street')->select_list('id', 'street')));
$filter_form->add('street_number')
->type('number');
// validates form and saves data
if($form->validate())
{
......
// save link
if (Iface_Model::type_has_link($im->type) &&
$im_connect_to && $im_connect_to->id)
{
$lm = new Link_Model($_POST['link_id'][$i]);
$lm->name = htmlspecialchars($_POST['link_name'][$i]);
$lm->medium = intval($_POST['medium'][$i]);
{
$roaming = new Link_Model();
$link_id = $_POST['link_id'][$i];
$roaming_id = $roaming->get_roaming();
$roaming = $roaming->find($roaming_id);
$name = $_POST['link_name'][$i];
$medium = $_POST['medium'][$i];
// don not connect to roaming
if ($link_id == $roaming_id)
{
$link_id = NULL;
// fix name
if (trim($name) == trim($roaming->name))
{
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$name = __('air') . ' ';
}
else
{
$name = __('cable') . ' ';
}
if ($im_connect_to->type == Iface_Model::TYPE_WIRELESS &&
$im_connect_to->wireless_mode == Iface_Model::WIRELESS_MODE_AP)
{
$name .= $im_connect_to->device->name;
$name .= ' - ' . $dm->name;
}
else
{
$name .= $dm->name . ' - ';
$name .= $im_connect_to->device->name;
}
// fix medium
if ($medium == Link_Model::MEDIUM_ROAMING)
{
if ($im->type == Iface_Model::TYPE_WIRELESS)
{
$medium = Link_Model::MEDIUM_AIR;
}
else
{
$medium = Link_Model::MEDIUM_CABLE;
}
}
}
}
$lm = new Link_Model($link_id);
$lm->name = htmlspecialchars($name);
$lm->medium = intval($medium);
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
$lm->bitrate = network::str2bytes($_POST['bitrate'][$i]);
$lm->duplex = ($_POST['duplex'][$i] == 1);
......
}
$lm->save_throwable();
// restrict count of connected devices to link
$max = Link_Model::get_max_ifaces_count($im->type);
if ($lm->id != $roaming_id &&
$max <= 2) // delete connected (port, eth)
{
foreach ($lm->ifaces as $i_del)
{
$i_del->link_id = null;
$i_del->save_throwable();
}
}
$im->link_id = $lm->id;
$im_connect_to->link_id = $lm->id;
$im_connect_to->save_throwable();
......
$view->content->eth_mediums = $eth_mediums;
$view->content->wl_mediums = $wl_mediums;
$view->content->port_mediums = $port_mediums;
$view->content->filter = $filter_form;
$view->content->filter = self::device_filter_form($default_filter_user);
$view->render(TRUE);
} // end of function add
......
return $grids;
}
/**
* Gets filter form fo devices
*
* @param integer $default_filter_user Pre-select default user
* @author Ondřej Fibich
* @see Devices_Controller#add
* @see Ifaces_Controller#add
* @return Filter_form
*/
public static function device_filter_form($default_filter_user = NULL)
{
$filter_form = new Filter_form();
$filter_form->add('subnet')
->type('select')
->values(ORM::factory('subnet')->select_list_by_net())
->css_class('filter_field_subnet');
$filter_form->add('type')
->type('select')
->values(ORM::factory('enum_type')->get_values(Enum_type_model::DEVICE_TYPE_ID));
$user_col = $filter_form->add('user')
->type('select')
->values(ORM::factory('user')->select_list(
'id', 'CONCAT(surname, \' \', name, \' - \', login)',
'surname'
));
if (!empty($default_filter_user))
{
$user_col->default(Filter_form::OPER_IS, $default_filter_user);
}
$filter_form->add('device_name')
->callback('json/device_name');
$filter_form->add('town')
->type('select')
->values(array_unique(ORM::factory('town')->select_list('id', 'town')));
$filter_form->add('street')
->type('select')
->values(array_unique(ORM::factory('street')->select_list('id', 'street')));
$filter_form->add('street_number')
->type('number');
return $filter_form;
}
}
freenetis/branches/testing/application/views/ifaces/show.php
<th><?php echo __('Medium') ?></th>
<td><?php echo Link_Model::get_medium_type($iface->link->medium) ?></td>
</tr>
<?php if ($iface->link->medium == Link_Model::MEDIUM_AIR && !empty($iface->link->wireless_ssid)): ?>
<tr>
<th><?php echo __('SSID') ?></th>
<td><?php echo $iface->link->wireless_ssid ?></td>
</tr>
<?php endif; ?>
<?php endif; ?>
</table>
<?php if ($iface->type == Iface_model::TYPE_VLAN): ?>
<table class="extended" style="float:left; margin-left:10px; width:360px;" cellspacing="0">
freenetis/branches/testing/application/views/ifaces/add.php
<h2><?php echo $headline ?></h2>
<?php if (isset($additional_info) && !empty($additional_info)): ?>
<br /><div class="status_message_warning"><?php echo $additional_info ?></div>
<?php endif; ?>
<br /><?php echo $form ?><br />
<div id="dialog_link_detail" style="display: none">
<form class="form">
<table class="form" cellspacing="0">
<tr>
<th><label><?php echo __('Name') ?>:</label></th>
<td><?php echo form::input('link_name_input', '', 'class="textbox"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Comment') ?>:</label></th>
<td><?php echo form::textarea('link_comment_input', '', 'class="textbox" rows="5" cols="20"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Medium') ?>:</label></th>
<td><?php echo form::dropdown('eth_medium_input', $eth_mediums, '', 'style="width:200px"') ?>
</td>
</tr>
<tr>
<th><label><?php echo __('Medium') ?>:</label></th>
<td><?php echo form::dropdown('wl_medium_input', $wl_mediums, '', 'style="width:200px"') ?>
</td>
</tr>
<tr>
<th><label><?php echo __('Medium') ?>:</label></th>
<td><?php echo form::dropdown('port_medium_input', $port_mediums, '', 'style="width:200px"') ?>
</td>
</tr>
<tr>
<th><label><?php echo __('Norm') ?>:</label></th>
<td><?php echo form::dropdown('norm_input', $norms, '', 'style="width:200px"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Bitrate') ?>:</label></th>
<td><?php echo form::input('bitrate_input', '', 'class="number textbox" style="width:100px; margin-right:5px;"') ?>
<?php echo form::dropdown('bitrate_unit_input', $bit_units) ?>
</td>
</tr>
<tr>
<th><label><?php echo __('Duplex') ?>:</label></th>
<td><?php echo form::dropdown('duplex_input', arr::bool()) ?></td>
</tr>
<tr>
<th><label><?php echo __('SSID') ?>:</label></th>
<td><?php echo form::input('ssid_input', '', 'class="textbox"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Frequency') ?>:</label></th>
<td><?php echo form::input('frequency_input', '', 'class="number textbox"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Channel') ?>:</label></th>
<td><?php echo form::input('channel_input','','class="number textbox"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Channel width') ?>:</label></th>
<td><?php echo form::input('channel_width_input', '', 'class="number textbox"') ?></td>
</tr>
<tr>
<th><label><?php echo __('Polarization') ?>:</label></th>
<td><?php echo form::dropdown('polarization_input', $polarizations, '', 'style="width:200px"') ?></td>
</tr>
</table>
<button class="submit" type="button"><?php echo __('Save') ?></button>
</form>
</div>
<div id="dialog_filter_devices" class="dispNone"><?php echo $filter ?></div>
freenetis/branches/testing/application/views/js/devices_add.php
$('#wl_medium_input').val($td.find('input[name^="medium["]').val());
$('#port_medium_input').val($td.find('input[name^="medium["]').val());
$bitrate = $td.find('input[name^="bitrate["]').val();
$('#bitrate_input').val(substr($bitrate, 0, $bitrate.length-1));
$('#bitrate_unit_input').val(substr($bitrate, -1));
var bitrate = $td.find('input[name^="bitrate["]').val();
$('#bitrate_input').val(substr(bitrate, 0, bitrate.length-1));
$('#bitrate_unit_input').val(substr(bitrate, -1));
$('#duplex_input').val($td.find('input[name^="duplex["]').val());
$('#ssid_input').val($td.find('input[name^="wireless_ssid["]').val());
......
case <?php echo Iface_Model::TYPE_PORT ?>:
$td.find('input[name^="medium["]').val($('#port_medium_input').val());
break;
};
}
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff