ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

main.inc.php
Go to the documentation of this file.
1 <?php
2 
6 
7 // if this is a display host screen then go ahead and make a puppet facts window
8 if ($extravars['window_name'] == 'html_desktop') {
9 
10  // Set up a generic where clause
11  $where = 'id > 0';
12 
13  // Start getting various record counts
14  list ($status, $host_count, $records) = db_get_records($onadb, 'hosts', $where, "", 0);
15  list ($status, $dns_count, $records) = db_get_records($onadb, 'dns', $where, "", 0);
16  list ($status, $interface_count, $records) = db_get_records($onadb, 'interfaces', $where, "", 0);
17  list ($status, $domain_count, $records) = db_get_records($onadb, 'domains', $where, "", 0);
18  list ($status, $subnet_count, $records) = db_get_records($onadb, 'subnets', $where, "", 0);
19  list ($status, $pool_count, $records) = db_get_records($onadb, 'dhcp_pools', $where, "", 0);
20  list ($status, $block_count, $records) = db_get_records($onadb, 'blocks', $where, "", 0);
21  list ($status, $vlan_campus_count, $records) = db_get_records($onadb, 'vlan_campuses', $where, "", 0);
22  list ($status, $config_archive_count, $records) = db_get_records($onadb, 'configurations', $where, "", 0);
23 
24  $title_left_html .= "&nbsp;Record Counts";
25 
26 
27  $modbodyhtml .= <<<EOL
28 <script type="text/javascript">
29  function record_counts_pie(rownum) {
30  // Function modified from code posted on http://www.phpied.com/canvas-pie/
31  //
32 
33  // source data table and canvas tag
34  var data_table = document.getElementById('record_counts');
35  var td_index = 1; // which TD contains the data
36  var canvas = document.getElementById('record_counts_pie');
37 
38  // exit if canvas is not supported
39  if (typeof canvas.getContext === 'undefined') {
40  return;
41  }
42 
43  // define some colors
44  var color = [];
45  color[0] = "#bbaaff";
46  color[1] = "#ffaaaa";
47  color[2] = "#8899ff";
48  color[3] = "#ddffaa";
49  color[4] = "#aaffee";
50  color[5] = "#66ddcc";
51  color[6] = "#dd6677";
52  color[7] = "#55DD88";
53 
54  // get the data[] from the table
55  var tds, data = [], value = 0, total = 0, bump = [];
56  var trs = data_table.getElementsByTagName('tr'); // all TRs
57  for (var i = 0; i < trs.length; i++) {
58  tds = trs[i].getElementsByTagName('td'); // all TDs
59 
60  if (tds.value === 0) continue; // no TDs here, move on
61 
62  bump[i] = 0;
63  if (i == rownum) bump[i] = 10;
64 
65  // get the value, update total
66  value = parseFloat(tds[td_index].innerHTML);
67  data[i] = value;
68  total += value;
69  }
70 
71  // get canvas context, determine radius and center
72  var ctx = canvas.getContext('2d');
73  var canvas_size = [canvas.width, canvas.height];
74  var radius = Math.min((canvas_size[0]-20), (canvas_size[1]-20)) / 2;
75  var center = [canvas_size[0]/2, canvas_size[1]/2];
76 
77  var sofar = 0; // keep track of progress
78 
79  // clear out the current contents
80  ctx.fillStyle = "rgb(255,255,255)";
81  ctx.fillRect(0,0,canvas.width,canvas.height);
82 
83  // loop through each table row
84  for (var piece = 0; piece < trs.length; piece++) {
85 
86  var thisvalue = data[piece] / total;
87 
88  ctx.beginPath();
89  ctx.moveTo(center[0], center[1]); // center of the pie
90 
91  ctx.arc( // draw next arc
92  center[0],
93  center[1],
94  (radius + bump[piece]),
95  Math.PI * (- 0.5 + 2 * sofar), // -0.5 sets set the start to be top
96  Math.PI * (- 0.5 + 2 * (sofar + thisvalue)),
97  false
98  );
99 
100  ctx.lineTo(center[0], center[1]); // line back to the center
101  ctx.closePath();
102  ctx.fillStyle = color[piece];
103  ctx.fill();
104 
105  sofar += thisvalue; // increment progress tracker
106  }
107 }
108 </script>
109 
110  <table cellspacing="0" border="0" cellpadding="0">
111  <tr>
112  <td nowrap="true" valign="top" style="padding: 15px;"><br/><canvas id="record_counts_pie" width="150" height="150"></canvas></td>
113  <td nowrap="true" valign="top" style="padding: 15px;">
114 
115  <table onmouseout="record_counts_pie(99)" id="record_counts" border=1 style="border-collapse: collapse;border-color: #999999;"s>
116  <tr onmouseover="record_counts_pie(0)"><td><a title="List Subnets" onClick="xajax_window_submit('search_results', 'search_form_id=>subnet_search_form');">Subnets</a></td><td>{$subnet_count}</td>
117  <tr onmouseover="record_counts_pie(1)"><td><a title="List Hosts" onClick="xajax_window_submit('search_results', 'search_form_id=>host_search_form');">Hosts</a></td><td>{$host_count}</td>
118  <tr onmouseover="record_counts_pie(2)"><td>Interfaces</td><td>{$interface_count}</td>
119  <tr onmouseover="record_counts_pie(3)"><td>DNS Records</td><td>{$dns_count}</td>
120  <tr onmouseover="record_counts_pie(4)"><td><a title="List DNS Domains" onClick="toggle_window('app_domain_list');">DNS Domains</a></td><td>{$domain_count}</td>
121  <tr onmouseover="record_counts_pie(5)"><td>DHCP Pools</td><td>{$pool_count}</td>
122  <tr onmouseover="record_counts_pie(6)"><td><a title="List Blocks" onClick="xajax_window_submit('search_results', 'search_form_id=>block_search_form');"> Blocks</a></td><td>{$block_count}</td>
123  <tr onmouseover="record_counts_pie(7)"><td><a title="List VLAN Campuses" onClick="xajax_window_submit('search_results', 'search_form_id=>vlan_campus_search_form');">VLAN Campuses</a></td><td>{$vlan_campus_count}</td>
124  <tr onmouseover="record_counts_pie(8)"><td>Config Archives</td><td>{$config_archive_count}</td>
125  </table>
126  </td>
127  </tr>
128 </table>
129 
130 <script type="text/javascript">
131  // Print the nice pie chart!
132  record_counts_pie(99);
133 </script>
134 
135 EOL;
136 
137 }
138 
139 
140 
141 ?>
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
$title_right_html
$title_right_html
Definition: main.inc.php:3
$modbodyhtml
$modbodyhtml
Definition: main.inc.php:5
EOL
EOL
Definition: main.inc.php:43
$title_left_html
$title_left_html
Definition: main.inc.php:3