Revize c1bdc1c4
Přidáno uživatelem Michal Kliment před více než 9 roky(ů)
application/controllers/devices.php | ||
---|---|---|
*/
|
||
class Devices_Controller extends Controller
|
||
{
|
||
/**
|
||
* Constructor, only test if networks is enabled
|
||
*/
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
|
||
// access control
|
||
if (!Settings::get('networks_enabled'))
|
||
Controller::error (ACCESS);
|
||
}
|
||
|
||
/**
|
||
* Index redirects to show all
|
||
*/
|
||
... | ... | |
$order_by_direction = 'ASC', $page_word = null, $page = 1)
|
||
{
|
||
// access control
|
||
if (!$this->acl_check_view(get_class($this), 'devices'))
|
||
if (!$this->acl_check_view('Devices_Controller', 'devices'))
|
||
Controller::error(ACCESS);
|
||
|
||
$filter_form = new Filter_form('d');
|
||
... | ... | |
$filter_form->add('street_number')
|
||
->type('number');
|
||
|
||
$filter_form->add('mac')
|
||
->label('MAC address')
|
||
->class('mac')
|
||
->callback('json/iface_mac');
|
||
|
||
$filter_form->add('comment');
|
||
|
||
$filter_form->add('cloud')
|
||
... | ... | |
->values(ORM::factory('cloud')->select_list());
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->get('record_per_page')))
|
||
$limit_results = (int) $this->input->get('record_per_page');
|
||
if (is_numeric($this->input->post('record_per_page')))
|
||
$limit_results = (int) $this->input->post('record_per_page');
|
||
|
||
$device_model = new Device_Model;
|
||
$total_devices = $device_model->count_all_devices($filter_form->as_sql());
|
||
... | ... | |
'filter' => $filter_form
|
||
));
|
||
|
||
if ($this->acl_check_new(get_class($this), 'devices'))
|
||
if ($this->acl_check_new('Devices_Controller', 'devices'))
|
||
{
|
||
$grid->add_new_button('devices/add', 'Add new device');
|
||
}
|
||
... | ... | |
'class' => 'popup_link'
|
||
));
|
||
}
|
||
|
||
if (module::e('notification') &&
|
||
$this->acl_check_new('Notifications_Controller', 'devices'))
|
||
{
|
||
$grid->add_new_button('notifications/devices'.server::query_string(), 'Notifications', array
|
||
(
|
||
'title' => __('Set notification to devices admins'),
|
||
));
|
||
}
|
||
|
||
$grid->order_field('device_id')
|
||
->label('ID')
|
||
... | ... | |
$grid->order_link_field('user_id')
|
||
->link('users/show', 'user_login');
|
||
|
||
if ($this->acl_check_view('Device_active_links_Controller', 'display_device_active_links'))
|
||
{
|
||
$grid->callback_field('device_grid')
|
||
->label('Device active links')
|
||
->callback('callback::device_active_links');
|
||
}
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Devices_Controller', 'devices'))
|
||
... | ... | |
$view->render(TRUE);
|
||
} // end of show_all function
|
||
|
||
/**
|
||
* Shows all DHCP servers with their access times
|
||
*
|
||
* @param int $limit_results
|
||
* @param string $order_by
|
||
* @param string $order_by_direction
|
||
* @param string $page_word
|
||
* @param int $page
|
||
*/
|
||
public function show_all_dhcp_servers($limit_results = 50,
|
||
$order_by = 'access_time', $order_by_direction = 'ASC',
|
||
$page_word = null, $page = 1)
|
||
{
|
||
// access control
|
||
if (!$this->acl_check_view('Devices_Controller', 'devices'))
|
||
Controller::error(ACCESS);
|
||
|
||
// check if subnets with DHCP server has set uped gateway
|
||
$subnets = ORM::factory('subnet')->get_all_dhcp_subnets_without_gateway();
|
||
|
||
if (count($subnets))
|
||
{
|
||
$subnet_links = array();
|
||
foreach ($subnets as $s)
|
||
{
|
||
$subnet_links[] = html::anchor('subnets/show/' . $s->id, $s->name);
|
||
}
|
||
|
||
$m = 'These subnets have not configured gateway (%s), set them please.';
|
||
status::mwarning($m, TRUE, implode(', ', $subnet_links));
|
||
}
|
||
|
||
$filter_form = new Filter_form('d');
|
||
|
||
$filter_form->add('access_time')
|
||
->type('date')
|
||
->label('Last access time');
|
||
|
||
$filter_form->add('name')
|
||
->callback('json/device_name');
|
||
|
||
$filter_form->add('type')
|
||
->type('select')
|
||
->values(ORM::factory('Enum_type')->get_values(Enum_type_model::DEVICE_TYPE_ID));
|
||
|
||
$filter_form->add('trade_name')
|
||
->callback('json/device_trade_name');
|
||
|
||
$filter_form->add('subnet_id')
|
||
->type('select')
|
||
->values(ORM::factory('subnet')->select_list())
|
||
->label('Subnet');
|
||
|
||
$filter_form->add('ip_address')
|
||
->callback('json/ip_address');
|
||
|
||
$filter_form->add('town')
|
||
->type('combo')
|
||
->callback('json/town_name');
|
||
|
||
$filter_form->add('street')
|
||
->type('combo')
|
||
->callback('json/street_name');
|
||
|
||
$filter_form->add('street_number')
|
||
->type('number');
|
||
|
||
$filter_form->add('comment');
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->post('record_per_page')))
|
||
$limit_results = (int) $this->input->post('record_per_page');
|
||
|
||
$device_model = new Device_Model();
|
||
$total_devices = $device_model->count_all_dhcp_servers($filter_form->as_sql());
|
||
|
||
// limit check
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_devices)
|
||
$sql_offset = 0;
|
||
|
||
// query
|
||
$devices = $device_model->get_all_dhcp_servers(array
|
||
(
|
||
'offset' => $sql_offset,
|
||
'limit' => (int) $limit_results,
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'filter_sql' => $filter_form->as_sql()
|
||
));
|
||
|
||
// headline
|
||
$headline = __('DHCP servers');
|
||
|
||
// grid of devices
|
||
$grid = new Grid('ddhcp_servers', null, array
|
||
(
|
||
'current' => $limit_results,
|
||
'selector_increace' => 50,
|
||
'selector_min' => 50,
|
||
'selector_max_multiplier' => 20,
|
||
'base_url' => Config::get('lang'). '/devices/show_all_dhcp_servers/'
|
||
. $limit_results.'/'.$order_by.'/'.$order_by_direction,
|
||
'uri_segment' => 'page',
|
||
'total_items' => $total_devices,
|
||
'items_per_page' => $limit_results,
|
||
'style' => 'classic',
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results,
|
||
'filter' => $filter_form
|
||
));
|
||
|
||
$grid->order_field('device_id')
|
||
->label('ID')
|
||
->class('center');
|
||
|
||
$grid->order_field('device_name')
|
||
->link('devices/show', 'device_name');
|
||
|
||
$grid->order_field('type_name')
|
||
->label('Type');
|
||
|
||
$grid->order_callback_field('access_time')
|
||
->callback('callback::dhcp_servers_last_access_diff_field')
|
||
->label('Last access time');
|
||
|
||
$actions = $grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view('Devices_Controller', 'devices'))
|
||
{
|
||
$actions->add_action('device_id')
|
||
->icon_action('show')
|
||
->url('devices/show');
|
||
}
|
||
|
||
$grid->datasource($devices);
|
||
|
||
// view
|
||
$view = new View('main');
|
||
$view->title = $headline;
|
||
$view->breadcrumbs = $headline;
|
||
$view->content = new View('show_all');
|
||
$view->content->headline = $headline;
|
||
$view->content->table = $grid;
|
||
$view->render(TRUE);
|
||
} // end of show_all_dhcp_servers
|
||
|
||
/**
|
||
* Function shows all devices of user.
|
||
*/
|
||
... | ... | |
Controller::error(RECORD);
|
||
|
||
// access control
|
||
if (!$this->acl_check_view(get_class($this), 'devices', $user->member_id))
|
||
if (!$this->acl_check_view('Devices_Controller', 'devices', $user->member_id))
|
||
Controller::error(ACCESS);
|
||
|
||
$device_model = new Device_Model();
|
||
... | ... | |
$order_by_direction = 'asc';
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->get('record_per_page')))
|
||
$limit_results = (int) $this->input->get('record_per_page');
|
||
if (is_numeric($this->input->post('record_per_page')))
|
||
$limit_results = (int) $this->input->post('record_per_page');
|
||
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_devices)
|
||
$sql_offset = 0;
|
||
... | ... | |
$base_grid->callback_field('ip_address')
|
||
->callback('callback::ip_address_field');
|
||
|
||
$base_grid->link_field('subnet_id')
|
||
->link('subnets/show', 'subnet_name')
|
||
->label('Subnet');
|
||
if ($this->acl_check_view('Subnets_Controller', 'subnet'))
|
||
{
|
||
$base_grid->link_field('subnet_id')
|
||
->link('subnets/show', 'subnet_name')
|
||
->label('Subnet');
|
||
}
|
||
else
|
||
{
|
||
$base_grid->field('subnet_name')
|
||
->label('Subnet');
|
||
}
|
||
|
||
if ($this->acl_check_view('Device_active_links_Controller', 'display_device_active_links'))
|
||
{
|
||
$base_grid->callback_field('show_by_user')
|
||
->label('Device active links')
|
||
->callback('callback::device_active_links');
|
||
}
|
||
|
||
$actions = $base_grid->grouped_action_field();
|
||
|
||
if ($this->acl_check_view(get_class($this), 'devices', $user->member_id))
|
||
if ($this->acl_check_view('Devices_Controller', 'devices', $user->member_id))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('show')
|
||
->url('devices/show');
|
||
}
|
||
|
||
if ($this->acl_check_edit(get_class($this), 'devices', $user->member_id))
|
||
if ($this->acl_check_edit('Devices_Controller', 'devices', $user->member_id))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('edit')
|
||
->url('devices/edit');
|
||
}
|
||
|
||
if ($this->acl_check_delete(get_class($this), 'devices', $user->member_id))
|
||
if ($this->acl_check_delete('Devices_Controller', 'devices', $user->member_id))
|
||
{
|
||
$actions->add_action('id')
|
||
->icon_action('delete')
|
||
... | ... | |
|
||
$member_id = $device->user->member_id;
|
||
|
||
if (!$this->acl_check_view(get_class($this), 'devices', $member_id))
|
||
if (!$this->acl_check_view('Devices_Controller', 'devices', $member_id))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
... | ... | |
if ($this->acl_check_new('Devices_Controller', 'engineer', $member_id))
|
||
{
|
||
$grid_device_engineers->add_new_button(
|
||
'device_engineers/add/' . $device_id, 'Add new device engineer'
|
||
'device_engineers/add/' . $device_id,
|
||
'Add new device engineer',
|
||
array
|
||
(
|
||
'class' => 'popup_link'
|
||
)
|
||
);
|
||
}
|
||
|
||
... | ... | |
|
||
$grid_device_engineers->datasource($de);
|
||
|
||
$active_links_model = new Device_active_link_Model();
|
||
|
||
$active_links = $active_links_model->get_device_active_links($device_id);
|
||
|
||
// device admins
|
||
$device_admin_model = new Device_admin_Model();
|
||
$da = $device_admin_model->get_device_admins($device_id);
|
||
... | ... | |
'total_items' => count($da)
|
||
));
|
||
|
||
if ($this->acl_check_edit(get_class($this), 'admin', $member_id))
|
||
if ($this->acl_check_edit('Devices_Controller', 'admin', $member_id))
|
||
{
|
||
$grid_device_admins->add_new_button(
|
||
'device_admins/edit/' . $device_id, 'Edit device admins'
|
||
... | ... | |
$view = new View('main');
|
||
$view->title = __('Device').' '.$device->name;
|
||
$view->breadcrumbs = $breadcrumbs->html();
|
||
$view->action_logs = action_logs::object_last_modif($device, $device_id);
|
||
$view->content = new View('devices/show');
|
||
$view->content->device = $device;
|
||
$view->content->device_type = $device_type;
|
||
... | ... | |
$view->content->ifaces = $device->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'];
|
||
$view->content->table_ip_addresses = isset($grids['ip_addresses']) ? $grids['ip_addresses'] : '';
|
||
$view->content->ifaces = $grids['ifaces'];
|
||
$view->content->vlan_ifaces = $grids['vlan_ifaces'];
|
||
$view->content->port_ifaces = $grids['ports'];
|
||
... | ... | |
$view->content->gpsx = !empty($gps) ? $gps_result->gpsx : '';
|
||
$view->content->gpsy = !empty($gps) ? $gps_result->gpsy : '';
|
||
$view->content->lang = Config::get('lang');
|
||
$view->content->active_links = $active_links;
|
||
$view->render(TRUE);
|
||
} // end of show
|
||
|
||
... | ... | |
* and new ip address assigned to this interface.
|
||
*
|
||
* @param integer $user_id
|
||
* @param integer $connection_request_id If device added from connection request
|
||
*/
|
||
public function add($user_id = null)
|
||
public function add($user_id = null, $connection_request_id = NULL)
|
||
{
|
||
if (!$this->acl_check_new(get_class($this), 'devices'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$selected_engineer = $this->session->get('user_id');
|
||
|
||
$gpsx = '';
|
||
... | ... | |
Controller::error(RECORD);
|
||
}
|
||
|
||
$member_id = $um->member_id;
|
||
|
||
if (!$this->acl_check_new('Devices_Controller', 'devices', $member_id))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$device_name = $um->surname;
|
||
$selected = $um->id;
|
||
$selected_country_id = $um->member->address_point->country_id;
|
||
$selected_street_id = $um->member->address_point->street_id;
|
||
$selected_street_number = $um->member->address_point->street_number;
|
||
$selected_town_id = $um->member->address_point->town_id;
|
||
|
||
$selected_street = ($um->member->address_point->street != NULL ?
|
||
$um->member->address_point->street->street." " :
|
||
"");
|
||
$selected_street .= $selected_street_number;
|
||
|
||
if ($um->member->address_point->town != NULL)
|
||
{
|
||
$selected_town = $um->member->address_point->town->town;
|
||
$selected_district = ($um->member->address_point->town->quarter != NULL ?
|
||
$um->member->address_point->town->quarter :
|
||
""
|
||
);
|
||
$selected_zip = $um->member->address_point->town->zip_code;
|
||
}
|
||
else
|
||
{
|
||
$selected_town = "";
|
||
$selected_district = "";
|
||
$selected_zip = "";
|
||
}
|
||
|
||
$gps = $um->member->address_point->get_gps_coordinates();
|
||
|
||
if ($gps)
|
||
... | ... | |
$gpsy = gps::real2degrees($gps->gpsy, FALSE);
|
||
}
|
||
|
||
$found_engineer = ORM::factory('device_engineer')->get_engineer_of_user($um->id);
|
||
$arr_users[$um->id] = $um->get_name_with_login();
|
||
|
||
if ($found_engineer)
|
||
// connection request
|
||
if (!empty($connection_request_id))
|
||
{
|
||
$selected_engineer = $found_engineer->id;
|
||
$cr_model = new Connection_request_Model($connection_request_id);
|
||
|
||
if (!$cr_model->id)
|
||
Controller::error(RECORD);
|
||
|
||
// device name
|
||
$device_name = $um->surname . '_' . $cr_model->device_type->get_value();
|
||
// all device templates
|
||
$arr_device_templates = array
|
||
(
|
||
NULL => '----- '.__('Select template').' -----'
|
||
) + ORM::factory('device_template')
|
||
->where('enum_type_id', $cr_model->device_type_id)
|
||
->select_list();
|
||
}
|
||
else
|
||
{
|
||
// all device templates
|
||
$arr_device_templates = array
|
||
(
|
||
NULL => '----- '.__('Select template').' -----'
|
||
) + ORM::factory('device_template')->select_list();
|
||
}
|
||
|
||
$arr_users[$um->id] = $um->get_name_with_login();
|
||
}
|
||
else
|
||
{
|
||
if (!$this->acl_check_new('Devices_Controller', 'devices'))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$member_id = NULL;
|
||
|
||
$um = new User_Model();
|
||
$selected = 0;
|
||
$selected_country_id = Settings::get('default_country');
|
||
$selected_street_id = 0;
|
||
$selected_street_number = '';
|
||
$selected_town_id = 0;
|
||
$device_name = '';
|
||
|
||
$arr_users = array
|
||
(
|
||
NULL => '----- '.__('select user').' -----'
|
||
) + $um->select_list_grouped();
|
||
|
||
// all device templates
|
||
$arr_device_templates = array
|
||
(
|
||
NULL => '----- '.__('Select template').' -----'
|
||
) + ORM::factory('device_template')->select_list();
|
||
}
|
||
|
||
// enum types for device
|
||
... | ... | |
NULL => '----- '.__('Select antenna').' -----'
|
||
) + Iface_Model::get_wireless_antennas();
|
||
|
||
// all device templates
|
||
$arr_device_templates = array
|
||
(
|
||
NULL => '----- '.__('Select template').' -----'
|
||
) + ORM::factory('device_template')->select_list();
|
||
|
||
// country
|
||
$arr_countries = ORM::factory('country')->select_list('id', 'country_name');
|
||
$arr_countries = ORM::factory('country')->where('enabled', 1)->select_list('id', 'country_name');
|
||
|
||
// streets
|
||
$arr_streets = array
|
||
... | ... | |
$port_mediums = Iface_Model::get_types_has_link_with_medium(Iface_Model::TYPE_PORT);
|
||
|
||
// list of engineers
|
||
if ($this->acl_check_edit('Devices_Controller', 'main_engineer'))
|
||
if ($this->acl_check_edit('Devices_Controller', 'engineer', $member_id))
|
||
{
|
||
$arr_engineers = $um->select_list_grouped();
|
||
}
|
||
... | ... | |
$arr_engineers[$engineer->id] = $engineer->get_full_name_with_login();
|
||
}
|
||
|
||
// Device active links
|
||
$device_active_links_model = new Device_active_link_Model();
|
||
|
||
$all_active_links = $device_active_links_model->get_all_active_links();
|
||
|
||
$active_links = array();
|
||
|
||
foreach($all_active_links AS $active_link)
|
||
{
|
||
if (!$active_link->name)
|
||
$active_links[$active_link->id] = $active_link->title;
|
||
else
|
||
$active_links[$active_link->id] = $active_link->name.' ('.$active_link->title.')';
|
||
}
|
||
|
||
// forge form
|
||
$form = new Forge('devices/add' . (isset($user_id) ? '/' . $user_id : ''));
|
||
$form = new Forge();
|
||
|
||
$form->set_attr('id', 'device_add_form');
|
||
|
||
... | ... | |
|
||
$group_device->input('device_name')
|
||
->label('Device name')
|
||
->value(($user_id) ? $um->surname : '')
|
||
->value($device_name)
|
||
->rules('required|length[2,200]')
|
||
->style('width: 520px');
|
||
|
||
... | ... | |
$group_device->dropdown('device_type')
|
||
->options($types)
|
||
->rules('required')
|
||
->selected(isset($cr_model) ? $cr_model->device_type_id : NULL)
|
||
->style('width: 200px');
|
||
|
||
$group_device->dropdown('device_template_id')
|
||
->options($arr_device_templates)
|
||
->label('Device template')
|
||
->rules('required')
|
||
->selected(isset($cr_model) ? $cr_model->device_template_id : NULL)
|
||
->style('width: 200px')
|
||
->add_button('device_templates');
|
||
|
||
... | ... | |
->label('PPPoE')
|
||
->options(arr::rbool());
|
||
|
||
if ($this->acl_check_new(get_class($this), 'login'))
|
||
if ($this->acl_check_new('Devices_Controller', 'login'))
|
||
{
|
||
$group_device_details->input('login')
|
||
->label('Username')
|
||
... | ... | |
->autocomplete('json/device_login');
|
||
}
|
||
|
||
if ($this->acl_check_new(get_class($this), 'password'))
|
||
if ($this->acl_check_new('Devices_Controller', 'password'))
|
||
{
|
||
$group_device_details->input('login_password')
|
||
->label('Password')
|
||
... | ... | |
->selected($selected_engineer)
|
||
->style('width: 200px');
|
||
|
||
$group_device_details->textarea('device_comment')
|
||
->label('Comment')
|
||
->rules('length[0,254]')
|
||
->style('width: 520px');
|
||
|
||
$group_payment = $form->group('Device repayments')->visible(FALSE);
|
||
|
||
$group_payment->input('price')
|
||
->rules('valid_numeric');
|
||
$group_device_details->html_textarea('device_comment')
|
||
->mode('simple')
|
||
->label('Comment');
|
||
|
||
$group_payment->input('payment_rate')
|
||
->label('Monthly payment rate')
|
||
->rules('valid_numeric')
|
||
->callback(array($this, 'valid_repayment'));
|
||
$group_device_details->dropdown('active_links[]')
|
||
->label('Device active links')
|
||
->options($active_links)
|
||
->multiple('multiple')
|
||
->size(10);
|
||
|
||
$group_payment->date('buy_date')
|
||
->label('Buy date')
|
||
->years(date('Y')-100, date('Y'));
|
||
if (Settings::get('finance_enabled'))
|
||
{
|
||
$group_payment = $form->group('Device repayments')->visible(FALSE);
|
||
|
||
$group_payment->input('price')
|
||
->rules('valid_numeric');
|
||
|
||
$group_payment->input('payment_rate')
|
||
->label('Monthly payment rate')
|
||
->rules('valid_numeric')
|
||
->callback(array($this, 'valid_repayment'));
|
||
|
||
$group_payment->date('buy_date')
|
||
->label('Buy date')
|
||
->years(date('Y')-100, date('Y'));
|
||
}
|
||
|
||
$group_address = $form->group('Address');
|
||
|
||
... | ... | |
$group_address->visible(!$um->id);
|
||
}
|
||
|
||
$group_address->dropdown('town_id')
|
||
->label('Town')
|
||
->rules('required')
|
||
->options($arr_towns)
|
||
->selected($selected_town_id)
|
||
->style('width: 200px')
|
||
->add_button('towns');
|
||
$address_point_server_active = Address_points_Controller::is_address_point_server_active();
|
||
|
||
$group_address->dropdown('street_id')
|
||
// If address database application is set show new form
|
||
if ($address_point_server_active)
|
||
{
|
||
$group_address->dropdown('country_id')
|
||
->label('Country')
|
||
->rules('required')
|
||
->options($arr_countries)
|
||
->style('width:200px')
|
||
->selected(($selected_country_id != NULL ? $selected_country_id : Settings::get('default_country')));
|
||
|
||
$group_address->input('town')
|
||
->label(__('Town').' - '.__('District'))
|
||
->rules('required')
|
||
->class('join1')
|
||
->value((isset($selected_town) ? $selected_town : ''));
|
||
|
||
$group_address->input('district')
|
||
->class('join2')
|
||
->value((isset($selected_district) ? $selected_district : ''));
|
||
|
||
$group_address->input('street')
|
||
->label('Street')
|
||
->options($arr_streets)
|
||
->selected($selected_street_id)
|
||
->add_button('streets')
|
||
->style('width: 200px');
|
||
|
||
$group_address->input('street_number')
|
||
->rules('length[1,50]')
|
||
->value($selected_street_number);
|
||
|
||
$group_address->dropdown('country_id')
|
||
->label('Country')
|
||
->rules('required')
|
||
->options($arr_countries)
|
||
->selected(Settings::get('default_country'))
|
||
->style('width: 200px');
|
||
->value((isset($selected_street) ? $selected_street : ''));
|
||
|
||
$group_address->input('zip')
|
||
->label('Zip code')
|
||
->rules('required')
|
||
->value((isset($selected_zip) ? $selected_zip : ''));
|
||
}
|
||
else
|
||
{
|
||
$group_address->dropdown('town_id')
|
||
->label('Town')
|
||
->rules('required')
|
||
->options($arr_towns)
|
||
->selected($selected_town_id)
|
||
->style('width: 200px')
|
||
->add_button('towns');
|
||
|
||
$group_address->dropdown('street_id')
|
||
->label('Street')
|
||
->options($arr_streets)
|
||
->selected($selected_street_id)
|
||
->add_button('streets')
|
||
->style('width: 200px');
|
||
|
||
$group_address->input('street_number')
|
||
->rules('length[1,50]')
|
||
->value($selected_street_number);
|
||
|
||
$group_address->dropdown('country_id')
|
||
->label('Country')
|
||
->rules('required')
|
||
->options($arr_countries)
|
||
->selected(Settings::get('default_country'))
|
||
->style('width: 200px');
|
||
}
|
||
|
||
$group_address->input('gpsx')
|
||
->label(__('GPS').' X: '.help::hint('gps_coordinates'))
|
||
... | ... | |
->rules('gps')
|
||
->value($gpsy);
|
||
|
||
$form->group('Ethernet interfaces');
|
||
$form->group('Wireless interfaces');
|
||
$form->group('Ports');
|
||
$form->group('Internal interfaces');
|
||
$form->group(html::image(array
|
||
(
|
||
'src' => '/media/images/icons/ifaces/ethernet.png')
|
||
) . ' ' . __('Ethernet interfaces'))->visible(TRUE);
|
||
|
||
$form->group(html::image(array
|
||
(
|
||
'src' => '/media/images/icons/ifaces/wireless.png')
|
||
) . ' ' . __('Wireless interfaces'))->visible(TRUE);
|
||
|
||
$form->group(html::image(array
|
||
(
|
||
'src' => '/media/images/icons/ifaces/port.png')
|
||
) . ' ' . __('Ports'))->visible(TRUE);
|
||
|
||
$form->group(html::image(array
|
||
(
|
||
'src' => '/media/images/icons/ifaces/internal.png')
|
||
) . ' ' . __('Internal interfaces'))->visible(TRUE);
|
||
|
||
// submit button
|
||
$form->submit('Confirm');
|
||
... | ... | |
$dm = new Device_Model();
|
||
|
||
$update_allowed_params = array();
|
||
|
||
$expired_subnets = array(); // #465
|
||
|
||
// gets number of maximum of acceptable repeating of operation
|
||
// after reaching of deadlock and time of waiting between
|
||
// other attempt to make transaction (#254)
|
||
$transaction_attempt_counter = 0;
|
||
$max_attempts = max(1, abs(Settings::get('db_trans_deadlock_repeats_count')));
|
||
$timeout = abs(Settings::get('db_trans_deadlock_repeats_timeout'));
|
||
|
||
// try to delete
|
||
while (TRUE)
|
||
|
||
$match = array();
|
||
|
||
// validate address
|
||
if ($address_point_server_active &&
|
||
(
|
||
!Address_points_Controller::is_address_point_valid(
|
||
$form_data['country_id'],
|
||
$form_data['town'],
|
||
$form_data['district'],
|
||
$form_data['street'],
|
||
$form_data['zip']
|
||
) ||
|
||
!preg_match('((ev\.č\.)?[0-9][0-9]*(/[0-9][0-9]*[a-zA-Z]*)*)', $form_data['street'], $match)
|
||
))
|
||
{
|
||
try
|
||
$group_address->street->add_error('required', __('Invalid address point.'));
|
||
}
|
||
else
|
||
{
|
||
// street
|
||
if ($address_point_server_active)
|
||
{
|
||
$dm->transaction_start();
|
||
|
||
// device //////////////////////////////////////////////////////
|
||
$device = new Device_Model();
|
||
$device->user_id = $form_data['user_id'];
|
||
|
||
if (!isset($user_id))
|
||
{
|
||
$um = new User_Model($device->user_id);
|
||
}
|
||
$street = trim(preg_replace(' ((ev\.č\.)?[0-9][0-9]*(/[0-9][0-9]*[a-zA-Z]*)*)', '', $form_data['street']));
|
||
|
||
if (empty($form_data['device_name']))
|
||
{
|
||
$device->name = $um->login.'_'.$types[$form_data['device_type']];
|
||
}
|
||
else
|
||
$number = $match[0];
|
||
}
|
||
|
||
// try to delete
|
||
while (TRUE)
|
||
{
|
||
try
|
||
{
|
||
$device->name = $form_data['device_name'];
|
||
}
|
||
$dm->transaction_start();
|
||
|
||
$device_template = new Device_template_Model($form_data['device_template_id']);
|
||
// device //////////////////////////////////////////////////////
|
||
$device = new Device_Model();
|
||
$device->user_id = $form_data['user_id'];
|
||
|
||
if ($device_template && $device_template->id)
|
||
{
|
||
$device->trade_name = $device_template->name;
|
||
}
|
||
if (!isset($user_id))
|
||
{
|
||
$um = new User_Model($device->user_id);
|
||
}
|
||
|
||
$device->type = $form_data['device_type'];
|
||
$device->PPPoE_logging_in = $form_data['PPPoE_logging_in'];
|
||
if (empty($form_data['device_name']))
|
||
{
|
||
$device->name = $um->login.'_'.$types[$form_data['device_type']];
|
||
}
|
||
else
|
||
{
|
||
$device->name = $form_data['device_name'];
|
||
}
|
||
|
||
if ($this->acl_check_new(get_class($this), 'login'))
|
||
{
|
||
$device->login = $form_data['login'];
|
||
}
|
||
$device_template = new Device_template_Model($form_data['device_template_id']);
|
||
|
||
if ($this->acl_check_new(get_class($this), 'password'))
|
||
{
|
||
$device->password = $form_data['login_password'];
|
||
}
|
||
|
||
$device->price = $form_data['price'];
|
||
$device->payment_rate = $form_data['payment_rate'];
|
||
$device->buy_date = date('Y-m-d', $form_data['buy_date']);
|
||
$device->comment = $form_data['device_comment'];
|
||
if ($device_template && $device_template->id)
|
||
{
|
||
$device->trade_name = $device_template->name;
|
||
}
|
||
|
||
// address point ///////////////////////////////////////////////////
|
||
$device->type = $form_data['device_type'];
|
||
$device->PPPoE_logging_in = $form_data['PPPoE_logging_in'];
|
||
|
||
// gps
|
||
$gpsx = NULL;
|
||
$gpsy = NULL;
|
||
|
||
if (!empty($form_data['gpsx']) && !empty($form_data['gpsy']))
|
||
{
|
||
$gpsx = doubleval($form_data['gpsx']);
|
||
$gpsy = doubleval($form_data['gpsy']);
|
||
if ($this->acl_check_new('Devices_Controller', 'login'))
|
||
{
|
||
$device->login = $form_data['login'];
|
||
}
|
||
|
||
if (gps::is_valid_degrees_coordinate($form_data['gpsx']))
|
||
if ($this->acl_check_new('Devices_Controller', 'password'))
|
||
{
|
||
$gpsx = gps::degrees2real($form_data['gpsx']);
|
||
$device->password = $form_data['login_password'];
|
||
}
|
||
|
||
if (gps::is_valid_degrees_coordinate($form_data['gpsy']))
|
||
if (Settings::get('finance_enabled'))
|
||
{
|
||
$gpsy = gps::degrees2real($form_data['gpsy']);
|
||
$device->price = $form_data['price'];
|
||
$device->payment_rate = $form_data['payment_rate'];
|
||
$device->buy_date = date('Y-m-d', $form_data['buy_date']);
|
||
}
|
||
}
|
||
|
||
$address_point_model = new Address_point_Model();
|
||
$device->comment = $group_device_details->device_comment->value; // not escaped
|
||
|
||
$ap = $address_point_model->get_address_point(
|
||
$form_data['country_id'], $form_data['town_id'],
|
||
$form_data['street_id'], $form_data['street_number'],
|
||
$gpsx, $gpsy
|
||
);
|
||
// address point ///////////////////////////////////////////////////
|
||
|
||
// add address point if there is no such
|
||
if (!$ap->id)
|
||
{
|
||
$ap->save_throwable();
|
||
}
|
||
|
||
// add GPS
|
||
if (!empty($gpsx) && !empty($gpsy))
|
||
{ // save
|
||
$ap->update_gps_coordinates($ap->id, $gpsx, $gpsy);
|
||
}
|
||
else
|
||
{ // delete gps
|
||
$ap->gps = '';
|
||
$ap->save_throwable();
|
||
}
|
||
// gps
|
||
$gpsx = NULL;
|
||
$gpsy = NULL;
|
||
|
||
$device->address_point_id = $ap->id;
|
||
$device->save_throwable();
|
||
|
||
// device engineer ////////////////////////////////////////////
|
||
if (!empty($form_data['gpsx']) && !empty($form_data['gpsy']))
|
||
{
|
||
$gpsx = doubleval($form_data['gpsx']);
|
||
$gpsy = doubleval($form_data['gpsy']);
|
||
|
||
$device_engineer = new Device_engineer_Model();
|
||
$device_engineer->device_id = $device->id;
|
||
$device_engineer->user_id = $form_data['first_engineer_id'];
|
||
$device_engineer->save();
|
||
if (gps::is_valid_degrees_coordinate($form_data['gpsx']))
|
||
{
|
||
$gpsx = gps::degrees2real($form_data['gpsx']);
|
||
}
|
||
|
||
// ifaces //////////////////////////////////////////////////////
|
||
if (gps::is_valid_degrees_coordinate($form_data['gpsy']))
|
||
{
|
||
$gpsy = gps::degrees2real($form_data['gpsy']);
|
||
}
|
||
}
|
||
|
||
$update_allowed_params = array();// reset
|
||
$post_use = isset($_POST['use']) ? $_POST['use'] : array();
|
||
$address_point_model = new Address_point_Model();
|
||
|
||
foreach ($post_use as $i => $v)
|
||
{
|
||
// skip not used
|
||
if ($v != 1)
|
||
if ($address_point_server_active)
|
||
{
|
||
continue;
|
||
}
|
||
// save iface
|
||
$im = new Iface_Model();
|
||
$im->device_id = $device->id;
|
||
$im->name = htmlspecialchars($_POST['name'][$i]);
|
||
$im->comment = htmlspecialchars($_POST['comment'][$i]);
|
||
$im->type = intval($_POST['type'][$i]);
|
||
|
||
if ($im->type == Iface_Model::TYPE_PORT)
|
||
{
|
||
$im->number = intval($_POST['number'][$i]);
|
||
$im->port_mode = intval($_POST['port_mode'][$i]);
|
||
$t = new Town_Model();
|
||
$s = new Street_Model();
|
||
$t_id = $t->get_town($form_data['zip'], $form_data['town'], $form_data['district'])->id;
|
||
$s_id = $s->get_street($street, $t_id)->id;
|
||
|
||
$ap = $address_point_model->get_address_point($form_data['country_id'], $t_id, $s_id, $number,
|
||
$gpsx, $gpsy);
|
||
}
|
||
else
|
||
{
|
||
$im->mac = htmlspecialchars($_POST['mac'][$i]);
|
||
$ap = $address_point_model->get_address_point(
|
||
$form_data['country_id'], $form_data['town_id'],
|
||
$form_data['street_id'], $form_data['street_number'],
|
||
$gpsx, $gpsy
|
||
);
|
||
}
|
||
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
// add address point if there is no such
|
||
if (!$ap->id)
|
||
{
|
||
$im->wireless_antenna = intval($_POST['wireless_antenna'][$i]);
|
||
$im->wireless_mode = intval($_POST['wireless_mode'][$i]);
|
||
$ap->save_throwable();
|
||
}
|
||
|
||
// add GPS
|
||
if (!empty($gpsx) && !empty($gpsy))
|
||
{ // save
|
||
$ap->update_gps_coordinates($ap->id, $gpsx, $gpsy);
|
||
}
|
||
else
|
||
{ // delete gps
|
||
$ap->gps = '';
|
||
$ap->save_throwable();
|
||
}
|
||
|
||
$device->address_point_id = $ap->id;
|
||
$device->save_throwable();
|
||
|
||
// device engineer ////////////////////////////////////////////
|
||
|
||
// can autosave?
|
||
$autosave_may = TRUE;
|
||
$device_engineer = new Device_engineer_Model();
|
||
$device_engineer->device_id = $device->id;
|
||
$device_engineer->user_id = $form_data['first_engineer_id'];
|
||
$device_engineer->save_throwable();
|
||
|
||
if (isset($_POST['connected_iface'][$i]))
|
||
// ifaces //////////////////////////////////////////////////////
|
||
|
||
$update_allowed_params = array();// reset
|
||
$post_use = isset($_POST['use']) ? $_POST['use'] : array();
|
||
|
||
foreach ($post_use as $i => $v)
|
||
{
|
||
// restrict blank fields
|
||
if (!(Iface_Model::type_has_ip_address($im->type) &&
|
||
Iface_Model::type_has_mac_address($im->type) &&
|
||
empty($im->mac) && (
|
||
!isset($_POST['ip'][$i]) ||
|
||
empty($_POST['ip'][$i]) ||
|
||
!valid::ip_address($_POST['ip'][$i])
|
||
)))
|
||
// skip not used
|
||
if ($v != 1)
|
||
{
|
||
continue;
|
||
}
|
||
// save iface
|
||
$im = new Iface_Model();
|
||
$im->device_id = $device->id;
|
||
$im->name = htmlspecialchars($_POST['name'][$i]);
|
||
$im->comment = htmlspecialchars($_POST['comment'][$i]);
|
||
$im->type = intval($_POST['type'][$i]);
|
||
|
||
if ($im->type == Iface_Model::TYPE_PORT)
|
||
{
|
||
$im->number = intval($_POST['number'][$i]);
|
||
$im->port_mode = intval($_POST['port_mode'][$i]);
|
||
}
|
||
else
|
||
{
|
||
// connected iface
|
||
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
|
||
$im->mac = htmlspecialchars($_POST['mac'][$i]);
|
||
}
|
||
|
||
// save link
|
||
if (Iface_Model::type_has_link($im->type) &&
|
||
$im_connect_to && $im_connect_to->id)
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$im->wireless_antenna = intval($_POST['wireless_antenna'][$i]);
|
||
$im->wireless_mode = intval($_POST['wireless_mode'][$i]);
|
||
}
|
||
|
||
// can autosave?
|
||
$autosave_may = TRUE;
|
||
|
||
if (isset($_POST['connected_iface'][$i]))
|
||
{
|
||
// restrict blank fields
|
||
if (!(Iface_Model::type_has_ip_address($im->type) &&
|
||
Iface_Model::type_has_mac_address($im->type) &&
|
||
empty($im->mac) && (
|
||
!isset($_POST['ip'][$i]) ||
|
||
empty($_POST['ip'][$i]) ||
|
||
!valid::ip_address($_POST['ip'][$i])
|
||
)))
|
||
{
|
||
// disable autosave
|
||
$autosave_may = FALSE;
|
||
|
||
$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)
|
||
// connected iface
|
||
$im_connect_to = new Iface_Model($_POST['connected_iface'][$i]);
|
||
|
||
// save link
|
||
if (Iface_Model::type_has_link($im->type) &&
|
||
$im_connect_to && $im_connect_to->id)
|
||
{
|
||
$link_id = NULL;
|
||
// fix name
|
||
if (trim($name) == trim($roaming->name))
|
||
// disable autosave
|
||
$autosave_may = FALSE;
|
||
|
||
$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)
|
||
{
|
||
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 .= ' - ' . $device->name;
|
||
}
|
||
else
|
||
{
|
||
$name .= $device->name . ' - ';
|
||
$name .= $im_connect_to->device->name;
|
||
}
|
||
|
||
// fix medium
|
||
if ($medium == Link_Model::MEDIUM_ROAMING)
|
||
$link_id = NULL;
|
||
// fix name
|
||
if (trim($name) == trim($roaming->name))
|
||
{
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$medium = Link_Model::MEDIUM_AIR;
|
||
$name = __('air') . ' ';
|
||
}
|
||
else
|
||
{
|
||
$medium = Link_Model::MEDIUM_CABLE;
|
||
$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 ($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 = 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);
|
||
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
|
||
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
|
||
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
|
||
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
|
||
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
|
||
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
|
||
}
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
|
||
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
|
||
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
|
||
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
|
||
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
|
||
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
|
||
}
|
||
|
||
$lm->save_throwable();
|
||
$lm->save_throwable();
|
||
|
||
// restrict count of connected devices to link
|
||
$max = Link_Model::get_max_ifaces_count($im->type);
|
||
// 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)
|
||
if ($lm->id != $roaming_id &&
|
||
$max <= 2) // delete connected (port, eth)
|
||
{
|
||
$i_del->link_id = null;
|
||
$i_del->save_throwable();
|
||
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();
|
||
}
|
||
}
|
||
}
|
||
|
||
$im->link_id = $lm->id;
|
||
$im_connect_to->link_id = $lm->id;
|
||
$im_connect_to->save_throwable();
|
||
// autosave (add) link
|
||
if (isset($_POST['link_autosave'][$i]) &&
|
||
$_POST['link_autosave'][$i] && $autosave_may)
|
||
{
|
||
$lm = new Link_Model();
|
||
$lm->name = htmlspecialchars($_POST['link_name'][$i]);
|
||
$lm->medium = intval($_POST['medium'][$i]);
|
||
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
|
||
$lm->bitrate = network::str2bytes($_POST['bitrate'][$i]);
|
||
$lm->duplex = ($_POST['duplex'][$i] == 1);
|
||
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
{
|
||
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
|
||
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
|
||
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
|
||
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
|
||
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
|
||
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
|
||
}
|
||
|
||
$lm->save_throwable();
|
||
$im->link_id = $lm->id;
|
||
}
|
||
}
|
||
|
||
// autosave (add) link
|
||
if (isset($_POST['link_autosave'][$i]) &&
|
||
$_POST['link_autosave'][$i] && $autosave_may)
|
||
{
|
||
$lm = new Link_Model();
|
||
$lm->name = htmlspecialchars($_POST['link_name'][$i]);
|
||
$lm->medium = intval($_POST['medium'][$i]);
|
||
$lm->comment = htmlspecialchars($_POST['link_comment'][$i]);
|
||
$lm->bitrate = network::str2bytes($_POST['bitrate'][$i]);
|
||
$lm->duplex = ($_POST['duplex'][$i] == 1);
|
||
$im->save_throwable();
|
||
|
||
if ($im->type == Iface_Model::TYPE_WIRELESS)
|
||
if (isset($_POST['ip'][$i]) && valid::ip_address($_POST['ip'][$i]))
|
||
{
|
||
$lm->wireless_ssid = htmlspecialchars($_POST['wireless_ssid'][$i]);
|
||
$lm->wireless_norm = intval($_POST['wireless_norm'][$i]);
|
||
$lm->wireless_frequency = intval($_POST['wireless_frequency'][$i]);
|
||
$lm->wireless_channel = intval($_POST['wireless_channel'][$i]);
|
||
$lm->wireless_channel_width = intval($_POST['wireless_channel_width'][$i]);
|
||
$lm->wireless_polarization = intval($_POST['wireless_polarization'][$i]);
|
||
$subnet_id = intval($_POST['subnet'][$i]);
|
||
|
||
$gateway = ($_POST['gateway'][$i] == 1);
|
||
|
||
// ip address is gatewayof subnet
|
||
if ($gateway)
|
||
{
|
||
$subnet = new Subnet_Model($subnet_id);
|
||
|
||
$gateway = $subnet->get_gateway();
|
||
|
||
// subnet has already have gateway
|
||
if ($gateway && $gateway->id)
|
||
throw new Exception(__('Error').': '.__('Subnet has already have gateway'));
|
||
}
|
||
|
||
// save IP address
|
||
$ipm = new Ip_address_Model();
|
||
$ipm->iface_id = $im->id;
|
||
$ipm->subnet_id = $subnet_id;
|
||
$ipm->member_id = NULL;
|
||
$ipm->ip_address = htmlspecialchars($_POST['ip'][$i]);
|
||
$ipm->dhcp = ($_POST['dhcp'][$i] == 1);
|
||
$ipm->gateway = $gateway;
|
||
$ipm->service = ($_POST['service'][$i] == 1);
|
||
$ipm->save_throwable();
|
||
|
||
// expired subnet
|
||
$expired_subnets[] = $ipm->subnet_id;
|
||
// allowed subnet to added IP
|
||
$update_allowed_params[] = array
|
||
(
|
||
'member_id' => $device->user->member_id,
|
||
'to_enable' => array($ipm->subnet_id)
|
||
);
|
||
}
|
||
}
|
||
|
||
// connection request //////////////////////////////////////////
|
||
|
||
$lm->save_throwable();
|
||
$im->link_id = $lm->id;
|
||
if (isset($cr_model))
|
||
{
|
||
// change connection request
|
||
$cr_model->state = Connection_request_Model::STATE_APPROVED;
|
||
$cr_model->decided_user_id = $this->user_id;
|
||
$cr_model->device_id = $device->id;
|
||
$cr_model->decided_at = date('Y-m-d H:i:s');
|
||
$cr_model->save_throwable();
|
||
}
|
||
|
||
// change connected from if member is applicant and if
|
||
// he is not connected yet
|
||
if ($device->user->member->type == Member_Model::TYPE_APPLICANT && (
|
||
empty($device->user->member->applicant_connected_from) ||
|
||
$device->user->member->applicant_connected_from == '0000-00-00'
|
||
))
|
||
{
|
||
// connected from now
|
||
$device->user->member->applicant_connected_from = date('Y-m-d');
|
||
$device->user->member->save_throwable();
|
||
}
|
||
|
||
$im->save_throwable();
|
||
// expired subnets (#465)
|
||
ORM::factory('subnet')->set_expired_subnets($expired_subnets);
|
||
|
||
if (isset($_POST['ip'][$i]) && valid::ip_address($_POST['ip'][$i]))
|
||
// connection request - notice /////////////////////////////////
|
||
|
||
// only if request made by owner of device and ovner not
|
||
// decided the request by him self
|
||
if (module::e('notification') && isset($cr_model) &&
|
||
$cr_model->member_id == $cr_model->added_user->member_id &&
|
||
$cr_model->member_id != $this->member_id)
|
||
{
|
||
// save IP address
|
||
$ipm = new Ip_address_Model();
|
||
$ipm->iface_id = $im->id;
|
||
$ipm->subnet_id = intval($_POST['subnet'][$i]);
|
||
$ipm->member_id = NULL;
|
||
$ipm->ip_address = htmlspecialchars($_POST['ip'][$i]);
|
||
$ipm->dhcp = ($_POST['dhcp'][$i] == 1);
|
||
$ipm->gateway = ($_POST['gateway'][$i] == 1);
|
||
$ipm->service = ($_POST['service'][$i] == 1);
|
||
$ipm->save_throwable();
|
||
|
||
// allowed subnet to added IP
|
||
$update_allowed_params[] = array
|
||
(
|
||
'member_id' => $device->user->member_id,
|
||
'to_enable' => array($ipm->subnet_id)
|
||
// create comment for user
|
||
$link = html::anchor('devices/show/' . $cr_model->device_id,
|
||
$cr_model->device->name);
|
||
$comment = '<table>'
|
||
. '<tr><th>' . __('Approved by') . ':</th>'
|
||
. '<td>' . $cr_model->decided_user->get_full_name() . '</td></tr>'
|
||
. '<tr><th>' . __('Date') . ':</th>'
|
||
. '<td>' . $cr_model->decided_at . '</td></tr>'
|
||
. '<tr><th>' . __('Device') . ':</th>'
|
||
. '<td>' . $link . '</td></tr>'
|
||
. '</table>';
|
||
|
||
// trigger notice for member
|
||
Message_Model::activate_special_notice(
|
||
Message_Model::CONNECTION_REQUEST_APPROVE,
|
||
$cr_model->member_id, $this->session->get('user_id'),
|
||
Notifications_Controller::ACTIVATE,
|
||
Notifications_Controller::KEEP, $comment
|
||
);
|
||
}
|
||
}
|
||
|
||
// done
|
||
$dm->transaction_commit();
|
||
// saves active links
|
||
if ($form_data['active_links'])
|
||
{
|
||
$active_links = $form_data['active_links'];
|
||
|
||
//Update allowed subnets after transaction is successfully commited
|
||
$error_added = TRUE; // throw error?
|
||
|
||
foreach ($update_allowed_params as $params)
|
||
{
|
||
try
|
||
foreach ($active_links AS $al)
|
||
{
|
||
$device_active_links_model->map_devices_to_active_link(array($device->id), $al);
|
||
}
|
||
}
|
||
|
||
// done ////////////////////////////////////////////////////
|
||
$dm->transaction_commit();
|
||
|
||
// Update allowed subnets after transaction is successfully commited
|
||
$error_added = TRUE; // throw error?
|
||
|
||
foreach ($update_allowed_params as $params)
|
||
{
|
||
Allowed_subnets_Controller::update_enabled(
|
||
$params['member_id'], $params['to_enable'],
|
||
array(), array(), $error_added
|
||
);
|
||
try
|
||
{
|
||
Allowed_subnets_Controller::update_enabled(
|
||
$params['member_id'], $params['to_enable'],
|
||
array(), array(), $error_added
|
||
);
|
||
}
|
||
catch (Exception $e)
|
||
{
|
||
$error_added = FALSE;
|
||
status::warning('Error - cannot update allowed subnets of member.');
|
||
}
|
||
}
|
||
catch (Exception $e)
|
||
|
||
if (isset($cr_model))
|
||
{
|
||
$error_added = FALSE;
|
||
status::warning('Error - cannot update allowed subnets of member.');
|
||
status::success('Connection request has been succesfully approved.');
|
||
}
|
||
else
|
||
{
|
||
status::success('Device has been successfully saved.');
|
Také k dispozici: Unified diff
Release 1.1.0