Revize 1452
Přidáno uživatelem Ondřej Fibich před více než 12 roky(ů)
freenetis/branches/network/application/models/device.php | ||
---|---|---|
GROUP BY name
|
||
", "$device_name%");
|
||
}
|
||
|
||
/**
|
||
* Function deletes relations from pivot table.
|
||
*
|
||
* @author Jiri Svitak
|
||
* @param $port_id
|
||
*/
|
||
public function delete_from_pivot_table($device_id)
|
||
{
|
||
$this->db->query("
|
||
DELETE FROM device_engineers
|
||
WHERE device_id = ?
|
||
", $device_id);
|
||
$this->db->query("
|
||
DELETE FROM device_admins
|
||
WHERE device_id = ?
|
||
", $device_id);
|
||
}
|
||
|
||
/**
|
||
* Returns all member's devices with debt payments
|
freenetis/branches/network/application/controllers/device_templates.php | ||
---|---|---|
|
||
$form->input('name')
|
||
->label('Trade name')
|
||
->rules('required');
|
||
->rules('required')
|
||
->autocomplete('json/device_trade_name');
|
||
|
||
$form->dropdown('enum_types')
|
||
->label('Type')
|
||
... | ... | |
$form->input('name')
|
||
->label('Trade name')
|
||
->rules('required')
|
||
->value($device_template_model->name);
|
||
->value($device_template_model->name)
|
||
->autocomplete('json/device_trade_name');
|
||
|
||
$form->dropdown('enum_types')
|
||
->label('Type')
|
freenetis/branches/network/application/controllers/devices.php | ||
---|---|---|
$yes_no_option = array(0 => __('no'), 1 => __('yes'));
|
||
|
||
// forge form
|
||
$form = new Forge('devices/add');
|
||
$form = new Forge('devices/add' . (isset($user_id) ? '/' . $user_id : ''));
|
||
|
||
$form->set_attr('id', 'device_add_form');
|
||
|
||
$group_device = $form->group('Device');
|
||
|
||
// name is not required, it is useful to name routers, access points, etc. only
|
||
$group_device->input('name')
|
||
$group_device->input('device_name')
|
||
->label('Device name')
|
||
->value(($user_id) ? $user_model->surname : '')
|
||
->rules('required|length[2,200]')
|
||
... | ... | |
->selected($selected)
|
||
->style('width: 250px');
|
||
|
||
$group_device->dropdown('type')
|
||
$group_device->dropdown('device_type')
|
||
->options($types)
|
||
->rules('required')
|
||
->style('width: 250px');
|
||
... | ... | |
|
||
$group_device_details = $form->group('Device detail')->visible(FALSE);
|
||
|
||
$group_device_details->input('trade_name')
|
||
->rules('length[2,50]')
|
||
->autocomplete('json/device_trade_name')
|
||
->style('width: 520px');
|
||
|
||
$group_device_details->dropdown('PPPoE_logging_in')
|
||
->label('PPPoE')
|
||
->options($yes_no_option);
|
||
... | ... | |
->selected($selected_engineer)
|
||
->style('width: 250px');
|
||
|
||
$group_device_details->textarea('comment')
|
||
$group_device_details->textarea('device_comment')
|
||
->label('Comment')
|
||
->rules('length[0,254]')
|
||
->style('width: 520px');
|
||
... | ... | |
$user_model = new User_Model($dm->user_id);
|
||
}
|
||
|
||
if (empty($form_data['name']))
|
||
if (empty($form_data['device_name']))
|
||
{
|
||
$dm->name = $user_model->login.'_'.$types[$form_data['type']];
|
||
$dm->name = $user_model->login.'_'.$types[$form_data['device_type']];
|
||
}
|
||
else
|
||
{
|
||
$dm->name = $form_data['name'];
|
||
$dm->name = $form_data['device_name'];
|
||
}
|
||
|
||
$dm->trade_name = htmlspecialchars($_POST['trade_name']);
|
||
$dm->type = $form_data['type'];
|
||
$dm->type = $form_data['device_type'];
|
||
$dm->PPPoE_logging_in = $form_data['PPPoE_logging_in'];
|
||
|
||
if ($this->acl_check_new(get_class($this), 'login'))
|
||
... | ... | |
$dm->price = $form_data['price'];
|
||
$dm->payment_rate = $form_data['payment_rate'];
|
||
$dm->buy_date = date('Y-m-d', $form_data['buy_date']);
|
||
$dm->comment = $form_data['comment'];
|
||
$dm->comment = $form_data['device_comment'];
|
||
|
||
// address point ///////////////////////////////////////////////////
|
||
|
||
... | ... | |
$gpsx = doubleval($form_data['gpsx']);
|
||
$gpsy = doubleval($form_data['gpsy']);
|
||
|
||
if (gps::is_valid_degrees_coordinate($form->gpsx->value))
|
||
if (gps::is_valid_degrees_coordinate($form_data['gpsx']))
|
||
{
|
||
$gpsx = gps::degrees2real($form->gpsx->value);
|
||
$gpsx = gps::degrees2real($form_data['gpsx']);
|
||
}
|
||
|
||
if (gps::is_valid_degrees_coordinate($form->gpsy->value))
|
||
if (gps::is_valid_degrees_coordinate($form_data['gpsy']))
|
||
{
|
||
$gpsy = gps::degrees2real($form->gpsy->value);
|
||
$gpsy = gps::degrees2real($form_data['gpsy']);
|
||
}
|
||
}
|
||
|
||
... | ... | |
// save IP address
|
||
$ipm = new Ip_address_Model();
|
||
$ipm->iface_id = $im->id;
|
||
$ipm->subnet_id = intval($_POST['subnet_id'][$i]);
|
||
$ipm->subnet_id = intval($_POST['subnet'][$i]);
|
||
$ipm->member_id = NULL;
|
||
$ipm->ip_address = htmlspecialchars($_POST['ip_address'][$i]);
|
||
$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);
|
||
... | ... | |
->value($device->name)
|
||
->style('width: 500px');
|
||
|
||
$form->input('trade_name')
|
||
->rules('length[1,50]')
|
||
->value($device->trade_name)
|
||
->autocomplete('json/device_trade_name');
|
||
|
||
$form->dropdown('type')
|
||
->label('Type')
|
||
->options($types)
|
||
... | ... | |
} // end of function edit
|
||
|
||
/**
|
||
* Deletes device including all its interfaces and ip adresses.
|
||
* Devices with ports are not deleted.
|
||
* Deletes device including all its interfaces and ip adresses, etc. (using FK)
|
||
*
|
||
* @author Jiri Svitak
|
||
* @author Ondrej Fibich
|
||
* @param integer $device_id
|
||
*/
|
||
public function delete($device_id = null)
|
||
... | ... | |
Controller::error(RECORD);
|
||
}
|
||
|
||
if (!$this->acl_check_delete(
|
||
'Devices_Controller', 'devices', $device->user->member_id
|
||
))
|
||
$mid = $device->user->member_id;
|
||
|
||
if (!$this->acl_check_delete('Devices_Controller', 'devices', $mid))
|
||
{
|
||
Controller::error(ACCESS);
|
||
}
|
||
|
||
$linkback = Path::instance()->previous();
|
||
|
||
if (url::slice(url_lang::uri($linkback),1,1) == 'show')
|
||
if (url::slice(url_lang::uri($linkback), 1, 1) == 'show')
|
||
{
|
||
$linkback = 'devices/show_all';
|
||
}
|
||
|
||
// count of deleted interfaces
|
||
$deleted_ifaces = 0;
|
||
// count of deleted ip adresses
|
||
$deleted_ips = 0;
|
||
// dependent interfaces and ports
|
||
$ifaces = $device->ifaces;
|
||
$ports = $device->ports;
|
||
// deleting of ports is not implemented yet
|
||
if (count($ports) > 0)
|
||
{
|
||
status::success(
|
||
__('Device still has at least one port.')." ".
|
||
__('Deleted').": $deleted_ifaces ".
|
||
__('Interfaces').", $deleted_ips IP",
|
||
FALSE
|
||
);
|
||
url::redirect($linkback);
|
||
}
|
||
// going through interfaces
|
||
foreach($ifaces as $iface)
|
||
{
|
||
// find vlan_ifaces
|
||
$vlan_ifaces = $iface->vlan_ifaces;
|
||
|
||
if (count($vlan_ifaces) > 0)
|
||
{
|
||
status::success(
|
||
__('Interface still has at least one VLAN interface.')." ".
|
||
__('Deleted').": $deleted_ifaces ".
|
||
__('Interfaces').", $deleted_ips IP",
|
||
FALSE
|
||
);
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
$ips = $iface->ip_addresses;
|
||
|
||
foreach($ips as $ip)
|
||
{
|
||
// before deleting IP address it is necessary to delete redirection from junction table first
|
||
Database::instance()->delete('messages_ip_addresses', array('ip_address_id' => $ip->id));
|
||
// delete IP address
|
||
$ip->delete();
|
||
$deleted_ips++;
|
||
}
|
||
|
||
$iface->delete();
|
||
$deleted_ifaces++;
|
||
}
|
||
// it deletes relations from pivot tables
|
||
$device->delete_from_pivot_table($device->id);
|
||
|
||
if ($device->delete())
|
||
{
|
||
status::success(
|
||
__('Device has been successfully deleted.')." ".
|
||
__('Deleted').": $deleted_ifaces ".
|
||
__('Interfaces').", $deleted_ips IP",
|
||
FALSE
|
||
);
|
||
status::success('Device has been successfully deleted.');
|
||
}
|
||
else
|
||
{
|
freenetis/branches/network/application/views/js/devices_add.php | ||
---|---|---|
// correct dropdown after adding of a template
|
||
$('#device_template_id').live('addOption', function ()
|
||
{
|
||
$('#type').trigger('change');
|
||
$('#device_type').trigger('change');
|
||
});
|
||
|
||
// on change type update form to proper functionality
|
||
$('#type').change(function ()
|
||
$('#device_type').change(function ()
|
||
{
|
||
var value = $(this).val();
|
||
|
Také k dispozici: Unified diff
Opravy:
- opravy pri pridavani zarizeni (#185)