Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1453

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

Upravy:
- vylepseni a opravy v doplnovani zarizeni pro pripojeni k - formular pro pridavani zarizeni (#185)
- pokud neni v systemu pritomny portebne locale je generovana chyba (#121)

Opravy:
- opravy v setlocate (#121)

Zobrazit rozdíly:

freenetis/branches/network/application/hooks/site_lang.php
Config::set('language', $locales[$lang]);
// Overwrite setlocale which has already been set before in Kohana::setup()
setlocale(LC_ALL, Config::get('language') . '.UTF-8');
setlocale(LC_NUMERIC, 'en_US');
if (setlocale(LC_ALL, Config::get('language') . '.UTF-8') === FALSE)
{
throw new ErrorException(
'Cannot setlocale to: ' . Config::get('language') . '.UTF-8. ' .
'Please generate locale in your system.'
);
}
// Decimal number are always written with .
if (setlocale(LC_NUMERIC, 'en_US.UTF-8') === FALSE)
{
throw new ErrorException(
'Cannot setlocale to: en_US.UTF-8. ' .
'Please generate locale in your system.'
);
}
// Finally set a language cookie for 6 months
cookie::set('lang', $lang, 15768000, '/');
freenetis/branches/network/application/models/iface.php
* @author Ondrej Fibich
* @param integer $user_id User identificator
* @param integer $type Type of interface for connection
* @param array $gps location of device - default member AP [optional]
* @return object Suitable iface or null
*/
public function get_iface_for_connecting_to_iface($user_id, $type)
public function get_iface_for_connecting_to_iface($user_id, $type, $gps = array())
{
$can_connect = Iface_Model::get_can_connect_to($type);
$usearch = array(User_Model::ASSOCIATION, $user_id);
$user = new User_Model($user_id);
if (count($can_connect))
{
if ($user->id && count($can_connect))
{
$usearch = array(User_Model::ASSOCIATION, $user->id);
// find current user interfaces and select oponent by link
$from_current = $this->db->query("
SELECT i2.*
SELECT i2.id AS iface_id, d2.id AS device_id
FROM devices d
JOIN ifaces i ON i.device_id = d.id
JOIN links l ON i.link_id = l.id
......
d.user_id = ? AND d2.user_id IN (" . implode(',', $usearch) . ")
ORDER BY d2.user_id
LIMIT 1
", $type, $user_id);
", $type, $user->id);
if ($from_current->current())
{
return $from_current->current();
}
// find nearest of org and user (using GPS)
$from_nearest = $this->db->query("
SELECT i2.*
FROM members m
JOIN users u ON u.member_id = m.id
JOIN address_points ap ON m.address_point_id = ap.id
JOIN devices d2 ON d2.user_id <> u.id
JOIN ifaces i2 ON i2.device_id = d2.id
JOIN address_points ap2 ON d2.address_point_id = ap2.id
WHERE u.id = ? AND i2.type IN(" . implode(',', $can_connect) . ") AND
X(ap.gps) IS NOT NULL AND X(ap2.gps) IS NOT NULL AND
u.id IN (" . implode(',', $usearch) . ")
ORDER BY SQRT(POW(X(ap.gps) - X(ap2.gps), 2) + POW(Y(ap.gps) - Y(ap2.gps), 2))
LIMIT 1
", $type, $user_id);
if ($from_nearest->current())
// get GPS
if (is_array($gps) && count($gps) == 2) // gps from params
{
return $from_nearest->current();
$gps['x'] = str_replace(',', '.', gps::degrees2real($gps['x']));
$gps['y'] = str_replace(',', '.', gps::degrees2real($gps['y']));
}
else // gps from member address point
{
$gps_ap = $user->member->address_point->get_gps_coordinates();
$gps['x'] = str_replace(',', '.', $gps_ap->gpsx);
$gps['y'] = str_replace(',', '.', $gps_ap->gpsy);
}
// find nearest of all in net (using GPS)
$from_nearest = $this->db->query("
SELECT i2.*
FROM members m
JOIN users u ON u.member_id = m.id
JOIN address_points ap ON m.address_point_id = ap.id
JOIN devices d2 ON d2.user_id <> u.id
JOIN ifaces i2 ON i2.device_id = d2.id
JOIN address_points ap2 ON d2.address_point_id = ap2.id
WHERE u.id = ? AND i2.type IN(" . implode(',', $can_connect) . ") AND
X(ap.gps) IS NOT NULL AND X(ap2.gps) IS NOT NULL
ORDER BY SQRT(POW(X(ap.gps) - X(ap2.gps), 2) + POW(Y(ap.gps) - Y(ap2.gps), 2))
LIMIT 1
", $type, $user_id);
if ($from_nearest->current())
// valid GPS?
if ($gps['x'] <= 0 && $gps['y'] <= 0)
{
return $from_nearest->current();
return NULL;
}
// find nearest in net (using GPS)
return $this->db->query("
SELECT *
FROM ((
SELECT i2.id AS iface_id, d2.id AS device_id, 2 AS priority
FROM devices d2
JOIN ifaces i2 ON i2.device_id = d2.id
JOIN address_points ap2 ON d2.address_point_id = ap2.id
WHERE i2.type IN(" . implode(',', $can_connect) . ") AND
d2.user_id IN (" . implode(',', $usearch) . ") AND
X(ap2.gps) IS NOT NULL AND Y(ap2.gps) IS NOT NULL
ORDER BY SQRT(POW(" . $gps['x'] . " - X(ap2.gps), 2) +
POW(" . $gps['y'] . " - Y(ap2.gps), 2))
LIMIT 1
) UNION (
SELECT i2.id AS iface_id, d2.id AS device_id, 1 AS priority
FROM devices d2
JOIN ifaces i2 ON i2.device_id = d2.id
JOIN address_points ap2 ON d2.address_point_id = ap2.id
WHERE i2.type IN(" . implode(',', $can_connect) . ") AND
X(ap2.gps) IS NOT NULL AND Y(ap2.gps) IS NOT NULL
ORDER BY SQRT(POW(" . $gps['x'] . " - X(ap2.gps), 2) +
POW(" . $gps['y'] . " - Y(ap2.gps), 2))
LIMIT 1
)
) i
ORDER BY i.priority DESC
LIMIT 1
")->current();
}
return NULL;
freenetis/branches/network/application/models/user.php
);
/**
* Model constructor
*
* @param numeric $id
*/
public function __construct($id = false)
{
parent::__construct($id);
}
/**
* Returns all users
*
* !!!!!! SECURITY WARNING !!!!!!
freenetis/branches/network/application/controllers/json.php
*
* @author Ondřej Fibich
*/
public function get_links_by_iface()
public function get_link_by_iface()
{
$iface = new Iface_Model($this->input->get('iface_id'));
......
}
/**
* Gets suggestion for connecting one type of interface on location given by
* member address point or by given GPS.
*
* @author Ondřej Fibich
* @see Devices_Controller#add
*/
public function get_suggestion_for_connecting_to()
{
$user_id = $this->input->get('user_id');
$gpsx = $this->input->get('gpsx');
$gpsy = $this->input->get('gpsy');
$gps = array();
if ($user_id)
{
if ($gpsx && $gpsy)
{
$gps = array('x' => $gpsx, 'y' => $gpsy);
}
$im = new Iface_Model();
echo json_encode(array
(
Iface_Model::TYPE_WIRELESS => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_WIRELESS, $gps
),
Iface_Model::TYPE_ETHERNET => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_ETHERNET, $gps
),
Iface_Model::TYPE_PORT => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_PORT, $gps
)
));
}
else
{
echo json_encode(array());
}
}
/**
* Returns all members in JSON format
*
* @author Michal Kliment
freenetis/branches/network/application/controllers/js.php
{
$this->address_point_streets();
$this->address_point_gps();
//$this->link_iface();
$im = new Iface_Model();
$subnet = new Subnet_Model();
$device = new Device_Model();
$arr_suggest_connected_to = array();
if (isset($user_id))
{
$arr_suggest_connected_to = array
(
Iface_Model::TYPE_WIRELESS => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_WIRELESS
),
Iface_Model::TYPE_ETHERNET => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_ETHERNET
),
Iface_Model::TYPE_PORT => $im->get_iface_for_connecting_to_iface(
$user_id, Iface_Model::TYPE_PORT
)
);
}
$this->views['devices_add'] = View::factory('js/devices_add');
$this->views['devices_add']->arr_subnets = $subnet->select_list_by_net();
$this->views['devices_add']->arr_devices = $device->select_list('id', 'name', 'user_id');
$this->views['devices_add']->arr_suggest_connected_to = $arr_suggest_connected_to;
}
private function _js_devices_edit()
freenetis/branches/network/application/controllers/devices.php
$enum_type_model = new Enum_type_Model();
$device_type = $enum_type_model->get_value($device->type);
$this->session->set('ssDevice_id', $device->id);
$iface_model = new Iface_Model;
$ifaces = $device->ifaces;
$ip_model = new Ip_address_Model;
$subnet_model = new Subnet_Model;
$i = 0;
$ip_iface = '';
$ip_ifaces = '';
$arr_ip = array();
foreach ($ifaces as $iface)
{
$ip_iface = $ip_model->where('iface_id', $iface->id)->find_all();
foreach ($ip_iface as $ip)
$ip_ifaces = $iface->ip_addresses;
foreach ($ip_ifaces as $ip)
{
$arr_ip[$i]['iface_id'] = $iface->id;
$arr_ip[$i]['ip_address'] = $ip->ip_address;
$subnet = $subnet_model->where('id', $ip->subnet_id)->find();
$arr_ip[$i]['name'] = $subnet->name;
$arr_ip[$i]['network_address'] = $subnet->network_address;
$arr_ip[$i]['netmask'] = $subnet->netmask;
$i++;
$arr_ip[$i]['name'] = $ip->subnet->name;
$arr_ip[$i]['network_address'] = $ip->subnet->network_address;
$arr_ip[$i++]['netmask'] = $ip->subnet->netmask;
}
}
......
$view->content->count_engineers = count($de);
$view->content->count_admins = count($da);
$view->content->ifaces = $ifaces;
$view->content->ip_iface = $ip_iface;
$view->content->ip_iface = $ip_ifaces;
$view->content->table_device_engineers = $grid_device_engineers;
$view->content->table_device_admins = $grid_device_admins;
$view->content->table_ip_addresses = $grids['ip_addresses'];
freenetis/branches/network/application/views/js/devices_add.php
// connecting suggestions
var suggest_connected_to = new Array();
<?php foreach ($arr_suggest_connected_to as $k => $v): if ($arr_suggest_connected_to[$k] != NULL): ?>
suggest_connected_to[<?php echo $k ?>] = {device_id : <?php echo $v->device_id ?>, iface_id : <?php echo $v->id ?>};
<?php endif; endforeach; ?>
/**
* Opens dialog for specifing of details of IP address of iface. Data
......
switch (parseInt($td.find('input[name^="type"]').val()))
{
case <?php echo Iface_Model::TYPE_WIRELESS ?>:
$('#eth_medium_input').parent().parent().hide();
$('#port_medium_input').parent().parent().hide();
break;
$('#eth_medium_input').parent().parent().hide();
$('#port_medium_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_ETHERNET ?>:
$('#wl_medium_input').parent().parent().hide();
$('#port_medium_input').parent().parent().hide();
$('#ssid_input').parent().parent().hide();
$('#norm_input').parent().parent().hide();
$('#frequency_input').parent().parent().hide();
$('#channel_input').parent().parent().hide();
$('#channel_width_input').parent().parent().hide();
$('#polarization_input').parent().parent().hide();
break;
$('#wl_medium_input').parent().parent().hide();
$('#port_medium_input').parent().parent().hide();
$('#ssid_input').parent().parent().hide();
$('#norm_input').parent().parent().hide();
$('#frequency_input').parent().parent().hide();
$('#channel_input').parent().parent().hide();
$('#channel_width_input').parent().parent().hide();
$('#polarization_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_PORT ?>:
$('#wl_medium_input').parent().parent().hide();
$('#eth_medium_input').parent().parent().hide();
$('#ssid_input').parent().parent().hide();
$('#norm_input').parent().parent().hide();
$('#frequency_input').parent().parent().hide();
$('#channel_input').parent().parent().hide();
$('#channel_width_input').parent().parent().hide();
$('#polarization_input').parent().parent().hide();
break;
$('#wl_medium_input').parent().parent().hide();
$('#eth_medium_input').parent().parent().hide();
$('#ssid_input').parent().parent().hide();
$('#norm_input').parent().parent().hide();
$('#frequency_input').parent().parent().hide();
$('#channel_input').parent().parent().hide();
$('#channel_width_input').parent().parent().hide();
$('#polarization_input').parent().parent().hide();
break;
};
// open dialog
......
switch (parseInt($td.find('input[name^="type"]').val()))
{
case <?php echo Iface_Model::TYPE_WIRELESS ?>:
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
break;
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_ETHERNET ?>:
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
break;
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_PORT ?>:
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
break;
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
break;
case <?php echo Iface_Model::TYPE_INTERNAL ?>:
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
break;
$('#port_number_input').parent().parent().hide();
$('#port_mode_input').parent().parent().hide();
$('#wireless_mode_input').parent().parent().hide();
$('#wireless_antenna_input').parent().parent().hide();
break;
};
// open dialog
......
method: 'get',
dataType: 'json',
async: 'false',
url: '<?php echo url_lang::base(); ?>json/get_links_by_iface?iface_id=' + iface_id,
url: '<?php echo url_lang::base(); ?>json/get_link_by_iface?iface_id=' + iface_id,
success: function (v)
{
if (v && parseInt(v.id))
......
});
$('#device_template_id').html(options.join(''));
})
});
// change add button href for prefilled enum type in add form dialog
var button = $('#device_template_id').parent().find('a');
......
button.attr('href', rtrim(parts[0], '0123456789/') + '/' + value + '?' + parts[1]);
}
});
// on change of user_id, or gps relocate suggest_connected_to array
$('#user_id, #gpsx, #gpsy').change(function ()
{
suggest_connected_to = new Array();
if (parseInt($('#user_id').val()))
{
$.getJSON('<?php echo url_lang::base() ?>json/get_suggestion_for_connecting_to', {
user_id: $('#user_id').val(), gpsx: $('#gpsx').val(), gpsy: $('#gpsy').val()
}, function(data)
{
suggest_connected_to = data;
});
}
});
// trigger at start
$('#user_id').trigger('change');

Také k dispozici: Unified diff