diff --git a/addressing.js b/addressing.js
index bf9fb66..2925002 100644
--- a/addressing.js
+++ b/addressing.js
@@ -179,7 +179,7 @@ function plugaddr_IsFilter(msg) {
function nameIsThere(params) {
var root_doc = params;
- var nameElm = $('input[id*="textfield_name"]');
+ var nameElm = $('input[id*="name_reserveip"]');
var typeElm = $('select[name="type"]');
var divNameItemElm = $('div[id="nameItem"]');
$.ajax({
diff --git a/ajax/addressing.php b/ajax/addressing.php
index 033daa7..c573828 100644
--- a/ajax/addressing.php
+++ b/ajax/addressing.php
@@ -34,7 +34,7 @@
Html::header_nocache();
if(isset($_POST['action']) && $_POST['action'] == 'isName'){
$item = new $_POST['type']();
- $datas = $item->find("`name` = '".$_POST['name']."'");
+ $datas = $item->find("`name` LIKE '".$_POST['name']."'");
if(count($datas) > 0){
echo json_encode(true);
}else{
@@ -48,8 +48,19 @@
} else {
_e('Access denied');
}
-}elseif(isset($_POST['action']) && $_POST['action'] == 'networkip'){
+
+}elseif(isset($_POST['action']) && $_POST['action'] == 'entities_networkip'){
IPNetwork::showIPNetworkProperties($_POST['entities_id']);
+
+}elseif(isset($_POST['action']) && $_POST['action'] == 'entities_location'){
+ Dropdown::show('Location', array('name' => "locations_id",
+ 'value' => $_POST["value"],
+ 'entity' => $_POST['entities_id']));
+
+}elseif(isset($_POST['action']) && $_POST['action'] == 'entities_fqdn'){
+ Dropdown::show('FQDN', array('name' => "fqdns_id",
+ 'value' => $_POST["value"],
+ 'entity'=> $_POST['entities_id']));
}elseif(isset($_POST['action']) && $_POST['action'] == 'showForm') {
$PluginAddressingReserveip = new PluginAddressingReserveip();
diff --git a/hook.php b/hook.php
index 3d01ea8..d073c7e 100644
--- a/hook.php
+++ b/hook.php
@@ -37,7 +37,7 @@ function plugin_addressing_install() {
&&!TableExists("glpi_plugin_addressing")
&& !TableExists("glpi_plugin_addressing_configs")) {
- $DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/empty-2.4.0.sql");
+ $DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/empty-3.0.0.sql");
} else {
@@ -85,6 +85,11 @@ function plugin_addressing_install() {
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-2.4.0.sql");
}
+ //Version 3.0.0
+ if (!FieldExists("glpi_plugin_addressing_addressings", "locations_id") && !FieldExists("glpi_plugin_addressing_addressings", "fqdns_id")) {
+ $DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-3.0.0.sql");
+ }
+
}
if ($update) {
@@ -120,7 +125,7 @@ function plugin_addressing_install() {
//Add all rights for current user profile
PluginAddressingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
//Drop old profile table : not used anymore
- $migration = new Migration("2.4.0");
+ $migration = new Migration("3.0.0");
$migration->dropTable('glpi_plugin_addressing_profiles');
return true;
@@ -133,7 +138,7 @@ function plugin_addressing_uninstall() {
include_once (GLPI_ROOT."/plugins/addressing/inc/profile.class.php");
include_once (GLPI_ROOT."/plugins/addressing/inc/menu.class.php");
- $migration = new Migration("2.3.0");
+ $migration = new Migration("3.0.0");
$tables = array("glpi_plugin_addressing_addressings",
"glpi_plugin_addressing_configs");
diff --git a/inc/addressing.class.php b/inc/addressing.class.php
index d4954e8..816ac4b 100644
--- a/inc/addressing.class.php
+++ b/inc/addressing.class.php
@@ -67,6 +67,16 @@ function getSearchOptions() {
$tab[4]['name'] = __('Ping free Ip', 'addressing');
$tab[4]['datatype'] = 'bool';
+ $tab[5]['table'] = 'glpi_locations';
+ $tab[5]['field'] = 'name';
+ $tab[5]['name'] = __('Location');
+ $tab[5]['datatype'] = 'dropdown';
+
+ $tab[6]['table'] = 'glpi_fqdns';
+ $tab[6]['field'] = 'name';
+ $tab[6]['name'] = FQDN::getTypeName(1);
+ $tab[6]['datatype'] = 'dropdown';
+
$tab[30]['table'] = $this->getTable();
$tab[30]['field'] = 'id';
$tab[30]['name'] = __('ID');
@@ -159,10 +169,11 @@ function showForm ($ID, $options=array()) {
echo "";
echo "
";
- echo "".__('Select the network', 'addressing')." | ";
+ echo "".__('Location')." | ";
echo "";
- Dropdown::show('Network', array('name' => "networks_id",
- 'value' => $this->fields["networks_id"]));
+ Dropdown::show('Location', array('name' => "locations_id",
+ 'value' => $this->fields["locations_id"],
+ 'entity' => $this->fields['entities_id']));
echo " | ";
if ($PluginAddressingConfig->fields["free_ip"]) {
@@ -170,7 +181,7 @@ function showForm ($ID, $options=array()) {
Dropdown::showYesNo('free_ip', $this->fields["free_ip"]);
echo "";
} else {
- echo "";
+ echo " | ";
echo Html::hidden('free_ip', array('value' => 0));
echo " | | ";
//echo " | | ";
@@ -178,9 +189,11 @@ function showForm ($ID, $options=array()) {
echo "
";
echo "";
- echo "".__('Detected subnet list', 'addressing')." | ";
+ echo "".FQDN::getTypeName(1)." | ";
echo "";
- $this->dropdownSubnet($ID>0 ? $this->fields["entities_id"] : $_SESSION["glpiactive_entity"]);
+ Dropdown::show('FQDN', array('name' => "fqdns_id",
+ 'value' => $this->fields["fqdns_id"],
+ 'entity'=> $this->fields['entities_id']));
echo " | ";
if ($PluginAddressingConfig->fields["double_ip"]) {
@@ -189,23 +202,17 @@ function showForm ($ID, $options=array()) {
echo "";
} else {
//echo " | | ";
- echo "";
+ echo " | ";
echo Html::hidden('double_ip', array('value' => 0));
echo " | | ";
}
echo "
";
echo "";
- echo "".__('First IP', 'addressing')." | "; // Subnet
+ echo "".__('Select the network', 'addressing')." | ";
echo "";
- echo ".";
- echo ".";
- echo ".";
- echo "";
+ Dropdown::show('Network', array('name' => "networks_id",
+ 'value' => $this->fields["networks_id"]));
echo " | ";
if ($PluginAddressingConfig->fields["reserved_ip"]) {
@@ -213,7 +220,7 @@ function showForm ($ID, $options=array()) {
Dropdown::showYesNo('reserved_ip',$this->fields["reserved_ip"]);
echo "";
} else {
- echo "";
+ echo " | ";
echo Html::hidden('reserved_ip', array('value' => 0));
echo " | | ";
//echo " | | ";
@@ -221,16 +228,9 @@ function showForm ($ID, $options=array()) {
echo "
";
echo "";
- echo "".__('Last IP', 'addressing')." | "; // Mask
+ echo "".__('Detected subnet list', 'addressing')." | ";
echo "";
- echo ".";
- echo ".";
- echo ".";
- echo "";
+ $this->dropdownSubnet($ID>0 ? $this->fields["entities_id"] : $_SESSION["glpiactive_entity"]);
echo " | ";
if ($PluginAddressingConfig->fields["use_ping"]) {
@@ -238,13 +238,45 @@ function showForm ($ID, $options=array()) {
Dropdown::showYesNo('use_ping', $this->fields["use_ping"]);
echo "";
} else {
- echo "";
+ echo " | ";
echo Html::hidden('use_ping', array('value' => 0));
echo " | | ";
//echo " | | ";
}
echo "
";
+ echo "";
+ echo "".__('First IP', 'addressing')." | "; // Subnet
+ echo "";
+ echo ".";
+ echo ".";
+ echo ".";
+ echo "";
+ echo " | ";
+ echo " | ";
+ echo " | ";
+ echo "
";
+
+ echo "";
+ echo "".__('Last IP', 'addressing')." | "; // Mask
+ echo "";
+ echo ".";
+ echo ".";
+ echo ".";
+ echo "";
+ echo " | ";
+ echo " | ";
+ echo " | ";
+ echo "
";
+
echo "";
echo "".__('Report for the IP Range', 'addressing')." | "; // Mask
echo "";
@@ -261,13 +293,11 @@ function showForm ($ID, $options=array()) {
echo " |
";
echo "";
- echo "";
- echo "";
- echo __('Comments')." | ";
- echo "".
- "";
- echo " | ";
- echo " | ";
+ echo "";
+ echo __('Comments')." | ";
+ echo "".
+ "";
+ echo " |
";
$this->showFormButtons($options);
diff --git a/inc/reserveip.class.php b/inc/reserveip.class.php
index cbc9f32..6613960 100644
--- a/inc/reserveip.class.php
+++ b/inc/reserveip.class.php
@@ -65,19 +65,21 @@ function reserveip($input = array())
// Find computer
$item = new $input['type']();
$id = 0;
- if (!$item->getFromDBByQuery("WHERE `name`='" . $input["name"] . "' AND `entities_id`=" . $input['entities_id'] . " LIMIT 1")) {
+ if (!$item->getFromDBByQuery("WHERE `name`='" . $input["name_reserveip"] . "' AND `entities_id`=" . $input['entities_id'] . " LIMIT 1")) {
// Add computer
- $id = $item->add(array("name" => $input["name"],
+ $id = $item->add(array("name" => $input["name_reserveip"],
"entities_id" => $input['entities_id'],
- 'states_id' => $input["states_id"],
- "comment" => $input['comment']));
+ "locations_id" => $input["locations_id"],
+ "states_id" => $input["states_id"],
+ "comment" => $input["comment"]));
} else {
$id = $item->getID();
//update item
$item->update(array("id" => $id,
"entities_id" => $input['entities_id'],
- 'states_id' => $input["states_id"],
- "comment" => $input['comment']));
+ "states_id" => $input["states_id"],
+ "locations_id" => $input["locations_id"],
+ "comment" => $input["comment"]));
}
// Add a new port
@@ -92,6 +94,7 @@ function reserveip($input = array())
"instantiation_type" => "NetworkPortAggregate",
"_create_children" => 1,
"NetworkName__ipaddresses" => array("-100" => $input["ip"]),
+ "NetworkName_fqdns_id" => $input["fqdns_id"],
"mac" => $input["mac"],
);
break;
@@ -105,6 +108,7 @@ function reserveip($input = array())
"instantiation_type" => "NetworkPortEthernet",
"_create_children" => 1,
"NetworkName__ipaddresses" => array("-100" => $input["ip"]),
+ "NetworkName_fqdns_id" => $input["fqdns_id"],
"mac" => $input["mac"],
);
break;
@@ -159,6 +163,9 @@ function showForm($ip, $id_addressing, $randmodal)
{
global $CFG_GLPI;
+ $addressing = new PluginAddressingAddressing();
+ $addressing->getFromDB($id_addressing);
+
$this->forceTable(PluginAddressingAddressing::getTable());
$this->initForm(-1);
$options['colspan'] = 2;
@@ -185,64 +192,100 @@ function showForm($ip, $id_addressing, $randmodal)
}
echo "";
- echo "
- " . __("Entity") . " |
+ $strict_entities = Profile_User::getUserEntities($_SESSION['glpiID'],false);
+ if (Session::haveAccessToOneOfEntities($strict_entities)
+ && Session::isViewAllEntities()) {
+ echo "
+ ".__("Entity")." |
";
- $rand = Entity::dropdown(array('name' => 'entities_id', 'entity' => $_SESSION["glpiactiveentities"]));
+ $rand = Entity::dropdown(array('name' => 'entities_id',
+ 'entity' => $_SESSION["glpiactiveentities"],
+ 'value' => $addressing->fields['entities_id']));
- $params = array('action' => 'networkip', 'entities_id' => '__VALUE__');
- Ajax::updateItemOnEvent("dropdown_entities_id" . $rand, 'networkip', $CFG_GLPI["root_doc"] . "/plugins/addressing/ajax/addressing.php", $params);
- echo " | | ";
+ $params = array('action' => 'entities_networkip', 'entities_id' => '__VALUE__');
+ Ajax::updateItemOnEvent("dropdown_entities_id".$rand, 'entities_networkip', $CFG_GLPI["root_doc"]."/plugins/addressing/ajax/addressing.php", $params);
+
+ $params = array('action' => 'entities_location', 'entities_id' => '__VALUE__', 'value' => $addressing->fields["locations_id"]);
+ Ajax::updateItemOnEvent("dropdown_entities_id".$rand, 'entities_location', $CFG_GLPI["root_doc"]."/plugins/addressing/ajax/addressing.php", $params);
+
+ $params = array('action' => 'entities_fqdn', 'entities_id' => '__VALUE__', 'value' => $addressing->fields["fqdns_id"]);
+ Ajax::updateItemOnEvent("dropdown_entities_id".$rand, 'entities_fqdn', $CFG_GLPI["root_doc"]."/plugins/addressing/ajax/addressing.php", $params);
+
+ echo " | ";
+ echo "
";
+ }
+
+ echo "";
+ echo "
+ ".__("Location")." |
+ ";
+
+ Dropdown::show('Location', array('name' => "locations_id",
+ 'value' => $addressing->fields["locations_id"],
+ 'entity' => $addressing->fields['entities_id']));
+ echo " | | ";
echo "
";
echo "";
echo "
- " . __("Type") . " |
+ ".__("Type")." |
";
- Dropdown::showFromArray('type', array(PluginAddressingReserveip::COMPUTER => Computer::getTypeName(),
- PluginAddressingReserveip::NETWORK => NetworkEquipment::getTypeName(),
- PluginAddressingReserveip::PRINTER => Printer::getTypeName()), array('on_change' => "nameIsThere(\"" . $CFG_GLPI['root_doc'] . "\");"));
+ Dropdown::showFromArray('type',array(PluginAddressingReserveip::COMPUTER => Computer::getTypeName(),
+ PluginAddressingReserveip::NETWORK => NetworkEquipment::getTypeName(),
+ PluginAddressingReserveip::PRINTER => Printer::getTypeName()), array('on_change' => "nameIsThere(\"".$CFG_GLPI['root_doc']."\");"));
echo " | | ";
echo "
";
echo "
- " . __("Name") . " : | ";
- $option = array('option' => "onChange=\"javascript:nameIsThere('" . $CFG_GLPI['root_doc'] . "');\"");
- Html::autocompletionTextField($this, "name", $option);
+ | ".__("Name")." : | ";
+ $option = array('option' => "onChange=\"javascript:nameIsThere('".$CFG_GLPI['root_doc']."');\"");
+ Html::autocompletionTextField($this,"name_reserveip",$option);
echo " | ";
- echo " ";
+ echo " ";
_e('Name already in use', 'addressing');
echo " |
";
echo "
- " . __("Status") . " : |
+ ".__("Status")." : |
";
Dropdown::show("State");
echo " |
|
";
echo "
- " . __("MAC address") . " : |
+ ".__("MAC address")." : |
|
|
";
+
+ echo "
+ ".FQDN::getTypeName(1)." : |
+ ";
+ Dropdown::show('FQDN', array('name' => "fqdns_id",
+ 'value' => $addressing->fields["fqdns_id"],
+ 'entity'=> $addressing->fields['entities_id']));
+ echo " | |
";
+
echo "
- " . __("Network") . " : |
- ";
- IPNetwork::showIPNetworkProperties($_SESSION["glpiactive_entity"]);
+ ".__("Network")." : |
+ ";
+ IPNetwork::showIPNetworkProperties($addressing->fields['entities_id']);
echo " |
| |
";
+
echo "
- " . __("Comments") . " : |
+ ".__("Comments")." : |
|
";
+
echo "
-
+
|
";
+
Html::closeForm();
}
diff --git a/setup.php b/setup.php
index 1c4ce38..81aa2f5 100644
--- a/setup.php
+++ b/setup.php
@@ -68,7 +68,7 @@ function plugin_version_addressing() {
return array(
'name' => _n('IP Adressing', 'IP Adressing', 2, 'addressing'),
- 'version' => '2.4.0',
+ 'version' => '3.0.0',
'author' => 'Gilles Portheault, Xavier Caillaud, Remi Collet, Nelly Mahu-Lasson',
'license' => 'GPLv2+',
'homepage' => 'https://github.com/pluginsGLPI/addressing',
diff --git a/sql/empty-3.0.0.sql b/sql/empty-3.0.0.sql
new file mode 100644
index 0000000..40ef8ec
--- /dev/null
+++ b/sql/empty-3.0.0.sql
@@ -0,0 +1,57 @@
+DROP TABLE IF EXISTS `glpi_plugin_addressing_addressings`;
+CREATE TABLE `glpi_plugin_addressing_addressings` (
+ `id` int(11) NOT NULL auto_increment,
+ `entities_id` int(11) NOT NULL default '0',
+ `name` varchar(255) collate utf8_unicode_ci default NULL,
+ `networks_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_networks (id)',
+ `locations_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_locations (id)',
+ `fqdns_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_fqdns (id)',
+ `begin_ip` varchar(255) collate utf8_unicode_ci default NULL,
+ `end_ip` varchar(255) collate utf8_unicode_ci default NULL,
+ `alloted_ip` tinyint(1) NOT NULL default '0',
+ `double_ip` tinyint(1) NOT NULL default '0',
+ `free_ip` tinyint(1) NOT NULL default '0',
+ `reserved_ip` tinyint(1) NOT NULL default '0',
+ `use_ping` tinyint(1) NOT NULL default '0',
+ `comment` text collate utf8_unicode_ci,
+ `is_deleted` tinyint(1) NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ KEY `name` (`name`),
+ KEY `entities_id` (`entities_id`),
+ KEY `networks_id` (`networks_id`),
+ KEY `is_deleted` (`is_deleted`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+DROP TABLE IF EXISTS `glpi_plugin_addressing_configs`;
+CREATE TABLE `glpi_plugin_addressing_configs` (
+ `id` int(11) NOT NULL auto_increment,
+ `alloted_ip` tinyint(1) NOT NULL default '0',
+ `double_ip` tinyint(1) NOT NULL default '0',
+ `free_ip` tinyint(1) NOT NULL default '0',
+ `reserved_ip` tinyint(1) NOT NULL default '0',
+ `use_ping` tinyint(1) NOT NULL default '0',
+ `used_system` tinyint(1) NOT NULL default '0',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+DROP TABLE IF EXISTS `glpi_plugin_addressing_filters`;
+CREATE TABLE `glpi_plugin_addressing_filters` (
+ `id` int(11) NOT NULL auto_increment,
+ `entities_id` int(11) NOT NULL default '0',
+ `plugin_addressing_addressings_id` int(11) NOT NULL default '0',
+ `name` varchar(255) collate utf8_unicode_ci default NULL,
+ `begin_ip` varchar(255) collate utf8_unicode_ci default NULL,
+ `end_ip` varchar(255) collate utf8_unicode_ci default NULL,
+ `type` varchar(255) collate utf8_unicode_ci default NULL,
+ PRIMARY KEY (`id`),
+ KEY `entities_id` (`entities_id`),
+ KEY `plugin_addressing_addressings_id` (`plugin_addressing_addressings_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+INSERT INTO `glpi_plugin_addressing_configs` VALUES ('1','1','1','1','1','0','0');
+
+INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAddressingAddressing',2,2,0);
+INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAddressingAddressing',3,6,0);
+INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAddressingAddressing',4,5,0);
+INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAddressingAddressing',1000,3,0);
+INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginAddressingAddressing',1001,4,0);
diff --git a/sql/update-3.0.0.sql b/sql/update-3.0.0.sql
new file mode 100644
index 0000000..2027ccb
--- /dev/null
+++ b/sql/update-3.0.0.sql
@@ -0,0 +1,3 @@
+ALTER TABLE `glpi_plugin_addressing_addressings`
+ ADD `locations_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_locations (id)',
+ ADD `fqdns_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_fqdns (id)';
\ No newline at end of file