r3154 - maintenance->trunk sync of changsets 3147~3152
[racktables] / popup.php
CommitLineData
38ee0db8 1<?php
f77323f1 2 require 'inc/interface.php';
38ee0db8 3 require 'inc/init.php';
cd3775e9
DO
4
5// Return a list of rack IDs, which are P or less positions
6// far from the given rack in its row.
7function getProximateRacks ($rack_id, $proximity = 0)
8{
9 $rack = spotEntity ('rack', $rack_id);
10 $rackList = listCells ('rack', $rack['row_id']);
11 doubleLink ($rackList);
12 $ret = array ($rack_id);
13 $todo = $proximity;
14 $cur_item = $rackList[$rack_id];
15 while ($todo and array_key_exists ('prev_key', $cur_item))
16 {
17 $cur_item = $rackList[$cur_item['prev_key']];
18 $ret[] = $cur_item['id'];
19 $todo--;
20 }
21 $todo = $proximity;
22 $cur_item = $rackList[$rack_id];
23 while ($todo and array_key_exists ('next_key', $cur_item))
24 {
25 $cur_item = $rackList[$cur_item['next_key']];
26 $ret[] = $cur_item['id'];
27 $todo--;
28 }
29 return $ret;
30}
31
32function findSparePorts ($port_id, $only_racks = array())
33{
34 $query = "SELECT id, type, object_id, name FROM Port WHERE " .
35 "id <> ${port_id} " .
36 "AND type IN (SELECT type2 FROM PortCompat WHERE type1 = (SELECT type FROM Port WHERE id = ${port_id})) " .
37 "AND reservation_comment IS NULL " .
38 "AND id NOT IN (SELECT porta FROM Link) " .
39 "AND id NOT IN (SELECT portb FROM Link) ";
40 if (count ($only_racks))
41 $query .= 'AND object_id IN (SELECT DISTINCT object_id FROM RackSpace WHERE rack_id IN (' .
42 implode (', ', $only_racks) . '))';
43 $result = useSelectBlade ($query, __FUNCTION__);
44 $ret = array();
45 while ($row = $result->fetch (PDO::FETCH_ASSOC))
46 {
47 $object = spotEntity ('object', $row['object_id']);
48 $ret[$row['id']] = $object['dname'] . ' ' . $row['name'];
49 }
50 return $ret;
51}
52
38ee0db8 53?>
39106006
DO
54<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
55<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" style="height: 100%;">
56<head>
57 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
b325120a 58<?php
4dc8e857 59 echo "<title>RackTables pop-up</title>\n";
39106006
DO
60 echo "<link rel=stylesheet type='text/css' href=pi.css />\n";
61 echo "<link rel=icon href='" . getFaviconURL() . "' type='image/x-icon' />";
62 echo '</head><body style="height: 100%;">';
39106006
DO
63 assertStringArg ('helper', __FILE__);
64 switch ($_REQUEST['helper'])
65 {
66 case 'portlist':
4dc8e857
DO
67 // FIXME: shouldn't this be derived from the URL?
68 $pageno = 'object';
69 $tabno = 'ports';
70 fixContext();
71 if (!permitted())
4dc8e857 72 renderAccessDenied();
39106006
DO
73 assertUIntArg ('port', __FILE__);
74 assertUIntArg ('object_id', __FILE__);
cd3775e9
DO
75 assertStringArg ('in_rack', __FILE__);
76 $localchoice = $_REQUEST['in_rack'] == 'y';
77 echo '<div style="background-color: #f0f0f0; border: 1px solid #3c78b5; padding: 10px; height: 100%; text-align: center; margin: 5px;"><h2>';
78 echo $localchoice ? 'Nearest spare ports:' : 'All spare ports:';
79 echo '</h2><form action="javascript:;">';
39106006
DO
80 $port_id = $_REQUEST['port'];
81 $object_id = $_REQUEST['object_id'];
cd3775e9
DO
82 $only_racks = array();
83 if ($_REQUEST['in_rack'] == 'y')
84 {
85 $port_info = getPortInfo ($port_id);
86 if ($port_info['object_id'])
87 {
88 $object = spotEntity ('object', $port_info['object_id']);
89 if ($object['rack_id'])
90 $only_racks = getProximateRacks ($object['rack_id'], getConfigVar ('PROXIMITY_RANGE'));
91 }
92 }
93 $spare_ports = findSparePorts ($port_id, $only_racks);
94 printSelect ($spare_ports, array ('name' => 'ports', 'id' => 'ports', 'size' => getConfigVar ('MAXSELSIZE')));
95 echo '<br><br>';
96 echo "<input type='submit' value='Link' onclick='".
39106006 97 "if (getElementById(\"ports\").value != \"\") {".
cd3775e9 98 " opener.location=\"process.php?page=object&tab=ports&op=linkPort&object_id=$object_id&port_id=$port_id&remote_port_id=\"+getElementById(\"ports\").value; ".
39106006
DO
99 " window.close();}'>";
100 echo '</form></div>';
101 break;
102 case 'inet4list':
4dc8e857
DO
103 $pageno = 'ipv4space';
104 $tabno = 'default';
105 fixContext();
106 if (!permitted())
4dc8e857 107 renderAccessDenied();
39106006 108 echo '<div style="background-color: #f0f0f0; border: 1px solid #3c78b5; padding: 10px; height: 100%; text-align: center; margin: 5px;">';
e8dd0422 109 echo '<h2>Choose a port:</h2><br><br>';
39106006
DO
110 echo '<form action="javascript:;">';
111 echo '<input type=hidden id=ip>';
112 echo '<select size=' . getConfigVar ('MAXSELSIZE') . ' id=addresses>';
23cdc7e9
DO
113 $addresses = getAllIPv4Allocations();
114 usort ($addresses, 'sortObjectAddressesAndNames');
115 foreach ($addresses as $address)
116 echo "<option value='${address['ip']}' onclick='getElementById(\"ip\").value=\"${address['ip']}\";'>" .
117 "${address['object_name']} ${address['name']} ${address['ip']}</option>\n";
39106006
DO
118 echo '</select><br><br>';
119 echo "<input type=submit value='Proceed' onclick='".
120 "if (getElementById(\"ip\")!=\"\") {".
121 " opener.document.getElementById(\"remoteip\").value=getElementById(\"ip\").value;".
122 " window.close();}'>";
123 echo '</form></div>';
124 break;
125 default:
126 showError ('Invalid parameter or internal error', __FILE__);
127 break;
128 }
e673ee24 129?>
e673ee24
DO
130</body>
131</html>