Skip to content

Commit ec80c54

Browse files
committed
Add Twig form IP Reservation
1 parent 2d6df1a commit ec80c54

10 files changed

Lines changed: 350 additions & 217 deletions

File tree

ajax/addressing.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* @version $Id$
45
-------------------------------------------------------------------------
@@ -27,17 +28,25 @@
2728
--------------------------------------------------------------------------
2829
*/
2930

30-
3131
use GlpiPlugin\Addressing\Filter;
3232
use GlpiPlugin\Addressing\Ping_Equipment;
3333
use GlpiPlugin\Addressing\ReserveIp;
34+
use function Safe\json_encode;
3435

3536
Session::checkRight('plugin_addressing', UPDATE);
3637

3738
Html::header_nocache();
3839
header("Content-Type: text/html; charset=UTF-8");
3940

40-
if (isset($_POST['action']) && $_POST['action'] == 'viewFilter') {
41+
if (isset($_GET['action']) && $_GET['action'] == 'isName') {
42+
$item = new $_GET['type']();
43+
$datas = $item->find(['name' => ['LIKE', $_GET['name']]]);
44+
if (count($datas) > 0) {
45+
echo json_encode(true);
46+
} else {
47+
echo json_encode(false);
48+
}
49+
} else if (isset($_POST['action']) && $_POST['action'] == 'viewFilter') {
4150
if (isset($_POST['items_id'])
4251
&& isset($_POST["id"])) {
4352
$filter = new Filter();
@@ -46,15 +55,19 @@
4655
echo __('Access denied');
4756
}
4857
} elseif (isset($_POST['action']) && $_POST['action'] == 'entities_networkip') {
58+
4959
IPNetwork::showIPNetworkProperties($_POST['entities_id']);
5060
} elseif (isset($_POST['action']) && $_POST['action'] == 'entities_location') {
61+
62+
echo __('Location');
5163
Dropdown::show('Location', ['name' => "locations_id",
52-
'value' => $_POST["value"],
53-
'entity' => $_POST['entities_id']]);
64+
'value' => $_POST["value"],
65+
'entity' => $_POST['entities_id']]);
5466
} elseif (isset($_POST['action']) && $_POST['action'] == 'entities_fqdn') {
67+
echo __('FQDN');
5568
Dropdown::show('FQDN', ['name' => "fqdns_id",
56-
'value' => $_POST["value"],
57-
'entity' => $_POST['entities_id']]);
69+
'value' => $_POST["value"],
70+
'entity' => $_POST['entities_id']]);
5871
} elseif ($_GET['action'] == 'ping') {
5972
Html::popHeader(__s('IP ping', 'addressing'), $_SERVER['PHP_SELF']);
6073

@@ -64,7 +77,7 @@
6477
}
6578
Html::popFooter();
6679
} else {
67-
Html::popHeader(__s('IP reservation', 'addressing'), $_SERVER['PHP_SELF']);
80+
Html::popHeader(ReserveIp::getTypeName());
6881

6982
if (filter_var($_GET["ip"], FILTER_VALIDATE_IP)) {
7083
$ReserveIp = new ReserveIp();

ajax/ipcomment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434

3535
use GlpiPlugin\Addressing\IpComment;
36+
use function Safe\json_encode;
3637

3738
Session::checkRight('plugin_addressing', UPDATE);
3839

front/addressing.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,13 @@
3535

3636
$Addressing = new Addressing();
3737

38-
if (isset($_GET['action']) && $_GET['action'] == 'isName') {
39-
if ($Addressing->canView() || Session::haveRight("config", UPDATE)) {
40-
$item = new $_GET['type']();
41-
$datas = $item->find(['name' => ['LIKE', $_GET['name']]]);
42-
if (count($datas) > 0) {
43-
echo json_encode(true);
44-
} else {
45-
echo json_encode(false);
46-
}
47-
}
38+
Html::header(Addressing::getTypeName(2), '', "tools", Addressing::class);
39+
40+
if ($Addressing->canView() || Session::haveRight("config", UPDATE)) {
41+
Search::show(Addressing::class);
4842
} else {
49-
Html::header(Addressing::getTypeName(2), '', "tools", Addressing::class);
43+
throw new AccessDeniedHttpException();
44+
}
5045

51-
if ($Addressing->canView() || Session::haveRight("config", UPDATE)) {
52-
Search::show(Addressing::class);
53-
} else {
54-
throw new AccessDeniedHttpException();
55-
}
46+
Html::footer();
5647

57-
Html::footer();
58-
}

front/reserveip.form.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,4 @@
4343
echo __("The address has been reserved", "addressing");
4444
echo "</div>";
4545
Html::popFooter();
46-
} else {
47-
Html::header(ReserveIp::getTypeName(), '', "tools", Addressing::class);
48-
if (filter_var($_REQUEST["ip"], FILTER_VALIDATE_IP)) {
49-
$reserveip->showReservationForm($_REQUEST["ip"], $_REQUEST["id_addressing"], $_REQUEST['rand']);
50-
}
51-
Html::footer();
5246
}

public/addressing.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

setup.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ function plugin_init_addressing()
7979
if (isset($_SESSION['glpiactiveprofile']['interface'])
8080
&& $_SESSION['glpiactiveprofile']['interface'] == 'central') {
8181
$PLUGIN_HOOKS[Hooks::ADD_CSS]['addressing'] = "addressing.css";
82-
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['addressing'] = 'addressing.js';
8382
}
8483
}
8584
}

src/Config.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ class Config extends CommonDBTM
4848

4949
public function showForm($ID, $options = [])
5050
{
51-
52-
$this->getFromDB($ID);
53-
51+
$this->initForm($ID, $options);
5452
TemplateRenderer::getInstance()->display(
5553
'@addressing/config.html.twig',
5654
[

src/Filter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,8 @@ public function getForbiddenStandardMassiveAction()
9696
public function showForm($ID, $options = [])
9797
{
9898

99-
if ($ID > 0) {
100-
$this->check($ID, READ);
101-
} else {
102-
$this->check(-1, CREATE, $options);
103-
}
104-
99+
$this->initForm($ID, $options);
105100
$options['colspan'] = 1;
106-
107101
$options['types'] = Addressing::dropdownItemtype();
108102
TemplateRenderer::getInstance()->display('@addressing/filter.html.twig', [
109103
'item' => $this,

0 commit comments

Comments
 (0)