Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 203

Přidáno uživatelem Michal Kliment před více než 15 roky(ů)

Dodelana i funkce edit u kontroleru IP adres.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/i18n/cs_CZ/texts.php
'select destination member' => 'Vyberte člena, kterému chcete peníze převést.',
'select device' => 'Vyber zařízení',
'select interface' => 'Vyber rozhraní',
'select vlan interface' => 'Vyber VLAN rozhraní',
'select only one subnet' => 'Vyberte jen jednu podsíť.',
'select only one type of iface' => 'Vyberte jen jeden typ rozhraní.',
'select port' => 'Vyber port',
freenetis/trunk/kohana/application/controllers/ip_addresses.php
$view->render(TRUE);
} // end of add function
function edit($ip_address_id = NULL)
{
//---- Get variable for narrow selecting of selectbox ----
$ssDevice_id = $this->session->get('ssDevice_id');
$ssIface_id = $this->session->get('ssIface_id');
$ssVlan_iface_id = $this->session->get('ssVlan_iface_id');
$this->form = new Forge(url_lang::base()."ip_addresses/edit/".$ip_address_id, '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$iface_model = new Iface_Model();
$vlan_iface_model = new Vlan_iface_Model();
$ip_address = new Ip_address_Model($ip_address_id);
if (!isset($ip_address_id) || $ip_address->id == 0) {
Controller::warning(1);
}
$this->ip_address_id = $ip_address_id;
$member_id = NULL;
$arr_ifaces = array();
$arr_vlan_ifaces = array();
$iface_selected = $ip_address->iface_id;
$vlan_iface_selected = $ip_address->vlan_iface_id;
if ($ip_address->iface_id && $ssIface_id == $ip_address->iface_id)
{
$ifaces = $iface_model->find_all_by_id($ssIface_id);
$vlan_ifaces = array();
}
else if ($ip_address->vlan_iface_id && $ssVlan_iface_id == $ip_address->vlan_iface_id)
{
$ifaces = array();
$vlan_ifaces = $vlan_iface_model->find_all_by_id($ssVlan_iface_id);
}
else
{
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
$vlan_ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all();
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
$arr_vlan_ifaces[0] = '----- '.url_lang::lang('texts.select vlan interface').' -----';
}
if (!$this->acl_check_edit('Devices_Controller', 'ip_address',$member_id)) Controller::error(1);
foreach ($ifaces as $iface) {
$arr_ifaces[$iface->id] = $iface->name;
}
foreach ($vlan_ifaces as $vlan_iface) {
$arr_vlan_ifaces[$vlan_iface->id] = $vlan_iface->name;
}
$subnet_model = new Subnet_Model();
$subnets = $subnet_model
->select("id","name","network_address as net_str",
"inet_aton(network_address) as net",
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")
->orderby('net')->find_all();
foreach ($subnets as $subnet)
{
$arr_subnets[$subnet->id] = $subnet->net_str.'/'.$subnet->mask.': '.$subnet->name;
}
if (count($arr_ifaces))
$this->form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name').':')->options($arr_ifaces)->selected($iface_selected);
if (count($arr_vlan_ifaces))
$this->form->dropdown('vlan_iface_id')->label(url_lang::lang('texts.VLAN interface name').':')->options($arr_vlan_ifaces)->selected($vlan_iface_selected)->callback(array($this, 'check_ifaces'));
$this->form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->rules('required')->value($ip_address->IP_address)
->callback(array($this, 'valid_ip'));
$this->form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name').':')
->options($arr_subnets)->selected($ip_address->subnet_id)
->rules('required');
//->class('ajax')->onchange('ajax_get_subnet(this.value)');
/**
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
* @todo Proper Ajax should be implemented - see http://learn.kohanaphp.com/2008/06/17/jquery-and-kohana-unobtrusive-ajax/
*
$form->group('')->label(url_lang::lang('texts.Subnet data'));
$form->input('subnet_name')->label(url_lang::lang('texts.Subnet name').':')->rules('required|length[3,250]')->callback(array($this, 'callback_subnet_selected'));
$form->input('subnet_network_address')->label(url_lang::lang('texts.Subnet network address').':')->rules('required|valid_ip')->callback(array($this, 'callback_subnet_selected'));
$form->input('subnet_netmask')->label(url_lang::lang('texts.Subnet netmask').':')->rules('required')->callback(array($this, 'callback_subnet_selected'));
$form->input('subnet_ospf_area_id')->label(url_lang::lang('texts.OSPF area ID').':')->rules('valid_digit')->callback(array($this, 'callback_subnet_selected'));
*/
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
//----- validate form and save data -----------------------------------
if($this->form->validate())
{
$form_data = $this->form->as_array();
foreach($form_data as $key => $value)
{
$form_data[$key] = htmlspecialchars($value);
}
$ip = new Ip_address_Model($ip_address_id);
if (isset($form_data['iface_id']) && (int) $form_data['iface_id'])
{
$ip->iface_id = $form_data['iface_id'];
$ip->vlan_iface_id = null;
}
else {
$ip->iface_id = null;
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
}
$ip->IP_address = $form_data['IP_address'];
$ip->subnet_id = $form_data['subnet_id'];
unset($form_data);
if ($ip->save()) {
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully updated.'));
if ($ssVlan_iface_id) url::redirect(url_lang::base().'vlan_ifaces/show/'.$ip->vlan_iface_id);
elseif ($ssIface_id) url::redirect(url_lang::base().'ifaces/show/'.$ip->iface_id);
else url::redirect(url_lang::base().'ip_addresses/show_all');
exit;
}
}
// end validate --------------------------------------------------
if ($ssVlan_iface_id) $link_back = html::anchor(url_lang::base().'vlan_ifaces/show/'.$ssVlan_iface_id, url_lang::lang('texts.Back to VLAN interface parameters'));
elseif ($ssIface_id) $link_back = html::anchor(url_lang::base().'ifaces/show/'.$ssIface_id, url_lang::lang('texts.Back to interface parameters'));
else $link_back = html::anchor(url_lang::base().'ip_addresses/show_all', url_lang::lang('texts.Back to IP addresses list'));
$view = new View('template');
$view->header = new View('base/header');
$view->header->title = url_lang::lang('texts.Edit IP address').' - '.$ip_address->IP_address;
$view->header->menu = Controller::render_menu();
$view->content = new View('form');
$view->content->form = $this->form->html();
$view->content->link_back = $link_back;
$view->content->headline = url_lang::lang('texts.Edit IP address').' - '.$ip_address->IP_address;
$view->footer = new View('base/footer');
$view->render(TRUE);
} // end of add function
/**
* Edits ip address.
* @param $ip_address_id id of ipaddress to edit
......
*/
function edit($ip_address_id = NULL)
{
$ip_address = new Ip_address_Model($ip_address_id);
if (!isset($ip_address_id) || $ip_address->id == 0) {
Controller::warning(1);
}
$this->form = new Forge(url_lang::base()."ip_addresses/edit/".$ip_address_id, '', 'POST', array('id' => 'article_form'));
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
$iface_model = new Iface_Model();
$vlan_iface_model = new Vlan_iface_Model();
$member_id = NULL;
$arr_ifaces = array();
$arr_vlan_ifaces = array();
$iface_selected = $ip_address->iface_id;
$vlan_iface_selected = $ip_address->vlan_iface_id;
$ifaces = $iface_model->select('id','name')->orderby('name')->find_all();
$vlan_ifaces = $vlan_iface_model->select('id','name')->orderby('name')->find_all();
$arr_ifaces[0] = '----- '.url_lang::lang('texts.select interface').' -----';
$arr_vlan_ifaces[0] = '----- '.url_lang::lang('texts.select vlan interface').' -----';
//if (!$this->acl_check_new('Devices_Controller', 'ip_address',$member_id)) Controller::error(1);
foreach ($ifaces as $iface) {
$arr_ifaces[$iface->id] = $iface->name;
}
foreach ($vlan_ifaces as $vlan_iface) {
$arr_vlan_ifaces[$vlan_iface->id] = $vlan_iface->name;
}
$subnet_model = new Subnet_Model();
$subnets = $subnet_model
->select("id","name","network_address as net_str",
"inet_aton(network_address) as net",
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")
->orderby('net')->find_all();
$arr_subnets[0] = '----- '.url_lang::lang('texts.select subnet').' -----';
foreach ($subnets as $subnet)
{
$arr_subnets[$subnet->id] = $subnet->net_str.'/'.$subnet->mask.': '.$subnet->name;
}
$this->form->dropdown('iface_id')->label(url_lang::lang('texts.Interface name').':')->options($arr_ifaces)->selected($iface_selected);
$this->form->dropdown('vlan_iface_id')->label(url_lang::lang('texts.VLAN interface name').':')->options($arr_vlan_ifaces)->selected($vlan_iface_selected)->callback(array($this, 'check_ifaces'));
$this->form->input('IP_address')->label(url_lang::lang('texts.IP address').':')->rules('required')
->callback(array($this, 'valid_ip'));
$this->form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet name').':')
->options($arr_subnets)
->rules('required');
//->class('ajax')->onchange('ajax_get_subnet(this.value)');
/**
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
* @todo Proper Ajax should be implemented - see http://learn.kohanaphp.com/2008/06/17/jquery-and-kohana-unobtrusive-ajax/
*
$form->group('')->label(url_lang::lang('texts.Subnet data'));
$form->input('subnet_name')->label(url_lang::lang('texts.Subnet name').':')->rules('required|length[3,250]')->callback(array($this, 'callback_subnet_selected'));
$form->input('subnet_network_address')->label(url_lang::lang('texts.Subnet network address').':')->rules('required|valid_ip')->callback(array($this, 'callback_subnet_selected'));
$form->input('subnet_netmask')->label(url_lang::lang('texts.Subnet netmask').':')->rules('required')->callback(array($this, 'callback_subnet_selected'));
$form->input('subnet_ospf_area_id')->label(url_lang::lang('texts.OSPF area ID').':')->rules('valid_digit')->callback(array($this, 'callback_subnet_selected'));
*/
$this->form->submit('submit')->value(url_lang::lang('texts.Save'));
special::required_forge_style($this->form, ' *', 'required');
//----- validate form and save data -----------------------------------
if($this->form->validate())
{
$form_data = $this->form->as_array();
foreach($form_data as $key => $value)
{
$form_data[$key] = htmlspecialchars($value);
}
$ip = new Ip_address_Model();
if (isset($form_data['iface_id']))
$ip->iface_id = $form_data['iface_id'];
if (isset($form_data['vlan_iface_id']))
$ip->vlan_iface_id = $form_data['vlan_iface_id'];
$ip->IP_address = $form_data['IP_address'];
$ip->subnet_id = $form_data['subnet_id'];
/**
* Removed by dulik for SVN rev. 98 - does not work with JavaScript disabled
else {
$subnet = new Subnet_Model();
$subnet->name = $form_data['subnet_name'];
$subnet->network_address = $form_data['subnet_network_address'];
$subnet->netmask = $form_data['subnet_netmask'];
$subnet->OSPF_area_id = $form_data['subnet_ospf_area_id'];
if ($subnet->save()) $ip->subnet_id = $subnet->id;
}
*/
unset($form_data);
if ($ip->save())
{
$this->session->set_flash('message', url_lang::lang('texts.IP address is successfully saved.'));
if ((bool)$ssVlan_iface_id) url::redirect(url_lang::base().'vlan_ifaces/show/'.$ip->vlan_iface_id);
else if ($ssIface_id) url::redirect(url_lang::base().'ifaces/show/'.$ip->iface_id);
else url::redirect(url_lang::base().'ip_addresses/show_all');
exit;
}
}
else
{
//$form->IP_address->value("ahoj"); //demo of how to fill a field after validation error
}
//----- end validate --------------------------------------------------
if ($vlan_iface_selected) $link_back = html::anchor(url_lang::base().'vlan_ifaces/show/'.$vlan_iface_selected, url_lang::lang('texts.Back to VLAN interface parameters'));
elseif ($iface_selected) $link_back = html::anchor(url_lang::base().'ifaces/show/'.$iface_selected, url_lang::lang('texts.Back to interface parameters'));
else $link_back = html::anchor(url_lang::base().'ip_addresses/show_all', url_lang::lang('texts.Back to IP addresses list'));
$view = new View('template');
$view->header = new View('base/header');
$view->header->title = url_lang::lang('texts.Edit IP address').' - '.$ip_address->IP_address;
$view->header->menu = Controller::render_menu();
$view->content = new View('form');
$view->content->form = $this->form->html();
$view->content->link_back = $link_back;
$view->content->headline = url_lang::lang('texts.Edit IP address').' - '.$ip_address->IP_address;
$view->footer = new View('base/footer');
$view->render(TRUE);
} // end of add functi
/**
* to do - comment

Také k dispozici: Unified diff