Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1480

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

Upravy:
- pridan javascriptovy validator pro existenci MAC adresy

Opravy:
- opraven dotaz pro filtrovani zarizeni
- opraven validator existence IP adresy

Zobrazit rozdíly:

freenetis/branches/network/application/i18n/cs_CZ/texts.php
'mac' => 'MAC',
'mac address' => 'MAC adresa',
'mac address already exists' => 'MAC adresa se již nachází v databázi',
'mac address is invalid' => 'MAC adresa je neplatná',
'mac restriction' => 'MAC restrikce',
'mac restriction file was successfully generated' => 'Soubor s MAC restrikcemi byl úspěšně vygenerován',
'magic switch :-)' => 'Kůzelné tlačítko :-)',
freenetis/branches/network/application/models/device.php
JOIN subnets s ON ip.subnet_id = s.id
) df
WHERE $filter_sql
GROUP BY d.id
GROUP BY device_id
ORDER BY IF(ISNULL(ip_address) OR LENGTH(ip_address) = 0, 1, 0),
INET_ATON(ip_address),
IF(ISNULL(device_name) OR LENGTH(device_name) = 0, 1, 0),
freenetis/branches/network/application/models/iface.php
/**
* Function gets count of specified mac address. Used for testing existence of that mac.
*
* @param $mac searched mac address
* @return unknown_type
* @param string $mac Searched mac address
* @param integer $iface_id Iface for edit restriction
* @return integer Count of MAC address without given iface
*/
public function get_count_of_mac($mac, $itype = NULL)
public function get_count_of_mac($mac, $iface_id = NULL)
{
$w = array('mac' => $mac);
if (is_numeric($itype))
if (is_numeric($iface_id))
{
$w['type'] = $itype;
$w['id <>'] = $iface_id;
}
return $this->db->where($w)->count_records('ifaces');
freenetis/branches/network/application/controllers/json.php
echo json_encode($arr_fees);
}
/**
* Performs action of mac_address_check jQuery frm validator.
*
* @author Ondrej Fibich
*/
public function mac_address_check()
{
$edit_id = intval($this->input->get('iface_id'));
$mac_str = trim($this->input->get('mac_address'));
// not required
if (empty($mac_str))
{
die(json_encode(array('state' => true)));
}
// checks mask
if (!valid::mac_address($mac_str))
{
die(json_encode(array
(
'state' => false,
'message' => __('MAC address is invalid.')
)));
}
// checks if exists this mac in database
if (ORM::factory('iface')->get_count_of_mac($mac_str, $edit_id) > 0)
{
die(json_encode(array
(
'state' => false,
'message' => __('MAC address already exists.')
)));
}
echo json_encode(array('state' => true));
}
/**
* Callback AJAX function to filter's whisper for member name
......
*/
public function ip_address_check()
{
$edit_id = intval($this->input->get('ip_address_id', 0));
$subnet_id = intval($this->input->get('subnet_id'), 0);
$edit_id = intval($this->input->get('ip_address_id'));
$subnet_id = intval($this->input->get('subnet_id'));
$ip_str = trim($this->input->get('ip_address'));
if (!$subnet_id && !$ip_str)
......
foreach ($ips as $ip)
{
// only for edit: check if ip_address is not still same
if ($edit_id && ($edit_id != $ip->id))
if ($edit_id && ($edit_id == $ip->id))
{
die(json_encode(array
(
'state' => false,
'message' => __('IP address already exists.')
)));
continue;
}
die(json_encode(array
(
'state' => false,
'message' => __('IP address already exists.')
)));
}
echo json_encode(array('state' => true));
freenetis/branches/network/application/views/js/devices_add.php
html_buffer.push('<label class="device_add_label">MAC: </label>');
html_buffer.push('<input type="text" name="mac[');
html_buffer.push(i);
html_buffer.push(']" class="mac_address');
html_buffer.push(']" class="mac_address mac_address_check');
// required if count is solid or minimal
if ((data['count'] != undefined) ||
freenetis/branches/network/application/views/js/base.php
{
return (value == '' || value.match(/^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/));
}, '<?php echo __('Invalid MAC address') ?>');
$.validator.addMethod('mac_address_check', function(value, element)
{
var ret = false;
$.ajax({
url: '<?php echo url_lang::base() ?>json/mac_address_check',
async: false,
dataType: 'json',
data: {mac_address: value},
success: function(result)
{
if(result.state)
{
ret = true;
}
else
{
$.validator.messages.mac_address = result.message;
}
}
});
return ret;
}, '<?php echo __('MAC address already exists.') ?>');
$.validator.addMethod('to_field', function(value)
{

Také k dispozici: Unified diff