Skip to content

Commit 2bed3af

Browse files
committed
Fix colors for reports
Use Twig for addressing form Clean scripts javascript
1 parent 8485f65 commit 2bed3af

7 files changed

Lines changed: 902 additions & 845 deletions

File tree

front/addressing.form.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* @version $Id$
45
-------------------------------------------------------------------------
@@ -41,21 +42,29 @@
4142

4243
if (isset($_POST["add"])) {
4344
$addressing->check(-1, CREATE, $_POST);
44-
if (!empty($_POST["name"])
45-
&& !empty($_POST["begin_ip"])
46-
&& !empty($_POST["end_ip"])) {
47-
$newID = $addressing->add($_POST);
45+
if (!empty($_POST["name"])) {
46+
if ($addressing->checkip($_POST)) {
47+
$_POST['begin_ip'] = (int) $_POST['begin_ip0'] . "." . (int) $_POST['begin_ip1'] . ".";
48+
$_POST['begin_ip'] .= (int) $_POST['begin_ip2'] . "." . (int) $_POST['begin_ip3'];
49+
$_POST['end_ip'] = (int) $_POST['end_ip0'] . "." . (int) $_POST['end_ip1'] . ".";
50+
$_POST['end_ip'] .= (int) $_POST['end_ip2'] . "." . (int) $_POST['end_ip3'];
51+
$newID = $addressing->add($_POST);
52+
if ($_SESSION['glpibackcreated']) {
53+
Html::redirect($addressing->getFormURL() . "?id=" . $newID);
54+
}
55+
Html::back();
56+
} else {
57+
Html::back();
58+
}
4859
} else {
4960
Session::addMessageAfterRedirect(
5061
__('Problem when adding, required fields are not here', 'addressing'),
5162
false,
5263
ERROR
5364
);
65+
Html::back();
5466
}
55-
if ($_SESSION['glpibackcreated']) {
56-
Html::redirect($addressing->getFormURL() . "?id=" . $newID);
57-
}
58-
Html::back();
67+
5968
} elseif (isset($_POST["delete"])) {
6069
$addressing->check($_POST['id'], DELETE);
6170
$addressing->delete($_POST);
@@ -70,18 +79,27 @@
7079
$addressing->redirectToList();
7180
} elseif (isset($_POST["update"])) {
7281
$addressing->check($_POST['id'], UPDATE);
73-
if (!empty($_POST["name"])
74-
&& !empty($_POST["begin_ip"])
75-
&& !empty($_POST["end_ip"])) {
76-
$addressing->update($_POST);
82+
if (!empty($_POST["name"])) {
83+
84+
if ($addressing->checkip($_POST)) {
85+
$_POST['begin_ip'] = (int) $_POST['begin_ip0'] . "." . (int) $_POST['begin_ip1'] . ".";
86+
$_POST['begin_ip'] .= (int) $_POST['begin_ip2'] . "." . (int) $_POST['begin_ip3'];
87+
$_POST['end_ip'] = (int) $_POST['end_ip0'] . "." . (int) $_POST['end_ip1'] . ".";
88+
$_POST['end_ip'] .= (int) $_POST['end_ip2'] . "." . (int) $_POST['end_ip3'];
89+
$addressing->update($_POST);
90+
Html::back();
91+
} else {
92+
Html::back();
93+
}
7794
} else {
7895
Session::addMessageAfterRedirect(
7996
__('Problem when adding, required fields are not here', 'addressing'),
8097
false,
8198
ERROR
8299
);
100+
Html::back();
83101
}
84-
Html::back();
102+
85103
} elseif (isset($_POST["search"])) {
86104
$addressing->checkGlobal(READ);
87105
Html::header(Addressing::getTypeName(2), '', "tools", Addressing::class);

public/addressing.js

Lines changed: 14 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,35 @@
1-
// Compute and Check the input data
2-
function plugaddr_Compute(msg) {
3-
4-
var ipdeb = new Array();
5-
var ipfin = new Array();
6-
var subnet = new Array();
7-
var netmask = new Array();
8-
var i;
9-
var val;
10-
11-
document.getElementById("plugaddr_range").innerHTML = "";
12-
document.getElementById("plugaddr_ipdeb").value = "";
13-
document.getElementById("plugaddr_ipfin").value = "";
14-
15-
for (var i = 0; i < 4; i++) {
16-
val=document.getElementById("plugaddr_ipdeb"+i).value;
17-
if (val=='' || isNaN(val) || parseInt(val)<0 || parseInt(val)>255) {
18-
document.getElementById("plugaddr_range").innerHTML=msg+" ("+val+")";
19-
return false;
20-
}
21-
ipdeb[i]=parseInt(val);
22-
23-
val=document.getElementById("plugaddr_ipfin"+i).value;
24-
if (val=='' || isNaN(val) || parseInt(val)<0 || parseInt(val)>255) {
25-
document.getElementById("plugaddr_range").innerHTML=msg+" ("+val+")";
26-
return false;
27-
}
28-
ipfin[i]=parseInt(val);
29-
}
30-
31-
if (ipdeb[0]>ipfin[0]) {
32-
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[0]+">"+ipfin[0]+")";
33-
return false;
34-
}
35-
if (ipdeb[0]==ipfin[0] && ipdeb[1]>ipfin[1]) {
36-
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[1]+">"+ipfin[1]+")";
37-
return false;
38-
}
39-
if (ipdeb[0]==ipfin[0] && ipdeb[1]==ipfin[1] && ipdeb[2]>ipfin[2]) {
40-
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[2]+">"+ipfin[2]+")";
41-
return false;
42-
}
43-
if (ipdeb[0]==ipfin[0] && ipdeb[1]==ipfin[1] && ipdeb[2]==ipfin[2] && ipdeb[3]>ipfin[3]) {
44-
document.getElementById("plugaddr_range").innerHTML=msg+" ("+ipdeb[3]+">"+ipfin[3]+")";
45-
return false;
46-
}
47-
document.getElementById("plugaddr_range").innerHTML=""+ipdeb[0]+"."+ipdeb[1]+"."+ipdeb[2]+"."+ipdeb[3]+" - "+ipfin[0]+"."+ipfin[1]+"."+ipfin[2]+"."+ipfin[3];
48-
document.getElementById("plugaddr_ipdeb").value=""+ipdeb[0]+"."+ipdeb[1]+"."+ipdeb[2]+"."+ipdeb[3];
49-
document.getElementById("plugaddr_ipfin").value=""+ipfin[0]+"."+ipfin[1]+"."+ipfin[2]+"."+ipfin[3];
50-
return true;
51-
}
52-
53-
// Check the input data (from onSubmit)
54-
function plugaddr_Check(msg) {
55-
56-
if (plugaddr_Compute(msg)) {
57-
return true;
58-
}
59-
alert(msg);
60-
return false;
61-
}
62-
631
// Display initial values
642
function plugaddr_Init(msg) {
653

66-
var ipdeb = new Array();
67-
var ipfin = new Array();
4+
var ipdeb;
5+
var ipfin;
686

69-
var ipdebstr = document.getElementById("plugaddr_ipdeb").value;
70-
var ipfinstr = document.getElementById("plugaddr_ipfin").value;
7+
var ipdebstr = document.getElementById("plugaddr_ipdeb").value;
8+
var ipfinstr = document.getElementById("plugaddr_ipfin").value;
719

72-
document.getElementById("plugaddr_range").innerHTML=""+ipdebstr+" - "+ipfinstr;
73-
74-
ipdeb=ipdebstr.split(".");
75-
ipfin=ipfinstr.split(".");
76-
for (i=0;i<4;i++) {
77-
document.getElementById("plugaddr_ipdeb"+i).value=ipdeb[i];
78-
document.getElementById("plugaddr_ipfin"+i).value=ipfin[i];
79-
}
10+
document.getElementById("plugaddr_range").innerHTML = "" + ipdebstr + " - " + ipfinstr;
8011
}
8112

82-
// Refresh the check message after onChange (from text input)
83-
// function plugaddr_ChangeNumber(msg) {
84-
//
85-
// var lst=document.getElementById("plugaddr_subnet");
86-
// if (lst!=null) {
87-
// lst.selectedIndex=0;
88-
// }
89-
//
90-
// plugaddr_Compute(msg);
91-
// }
92-
93-
// Refresh the check message after onChange (from list)
94-
// function plugaddr_ChangeList(id,msg) {
95-
//
96-
// var i;
97-
// var lst=document.getElementById(id);
98-
// if (lst.value == "0") {
99-
// return;
100-
// }
101-
// var champ=lst.value.split("/");
102-
// var subnet=champ[0].split(".");
103-
// var netmask=champ[1].split(".", 4);
104-
// var ipdeb = new Array();
105-
// var ipfin = new Array();
106-
//
107-
// netmask[3] = parseInt(netmask[3]).toString();
108-
// if (lst.selectedIndex>0) {
109-
// for (var i=0;i<4;i++) {
110-
// ipdeb[i]=subnet[i]&netmask[i];
111-
// ipfin[i]=ipdeb[i]|(255-netmask[i]);
112-
// if (i==3) {
113-
// ipdeb[3]++;
114-
// ipfin[3]--;
115-
// }
116-
// document.getElementById("plugaddr_ipdeb"+i).value=ipdeb[i];
117-
// document.getElementById("plugaddr_ipfin"+i).value=ipfin[i];
118-
// }
119-
// plugaddr_Compute(msg);
120-
// }
121-
// }
122-
12313
function nameIsThere(params) {
12414
var root_doc = params;
12515
var nameElm = $('input[id*="name_reserveip"]');
12616
var typeElm = $('select[name="type"]');
12717
var divNameItemElm = $('div[id="nameItem"]');
12818
$.ajax({
129-
url: root_doc + '/front/addressing.php',
130-
type: "GET",
131-
dataType: "json",
132-
data: {
19+
url: root_doc + '/front/addressing.php',
20+
type: "GET",
21+
dataType: "json",
22+
data: {
13323
action: 'isName',
13424
name: (nameElm.length != 0) ? nameElm.val() : '0',
13525
type: (typeElm.length != 0) ? typeElm.val() : '0',
136-
},
137-
success: function (json) {
26+
},
27+
success: function (json) {
13828
if (json) {
13929
divNameItemElm.show();
14030
} else {
141-
divNameItemElm.hide();
31+
divNameItemElm.hide();
14232
}
143-
}
144-
});
33+
}
34+
});
14535
}

0 commit comments

Comments
 (0)