function display_content() { $result = getMachineNumberByState(); $count = $result['count']; $days = $result['days']; $jsonCount = json_encode($count); $jsonDays = json_encode($days); $lessThanText = json_encode(_T("Less than %s days:\r\n %percent% (%d computers)", "glpi")); $moreThanText = json_encode(_T("More than %s days:\r\n %percent% (%d computers)", "glpi")); $urlRedirect = json_encode(urlStrRedirect("base/computers/createStaticGroup")); print _T("Latest Inventory Date", "glpi"); echo <<<INVENTORY <div id="inventory-graphs"></div> <script type="text/javascript"> var machineCount = {$jsonCount}, days = {$jsonDays}, lessThanText = {$lessThanText}, moreThanText = {$moreThanText}, urlRedirect = {$urlRedirect}, r = Raphael("inventory-graphs", 200, 300), radius = 80, x = 90, y = 90; var data = []; var legend = []; var colors = []; var href = []; if (machineCount.green) { var legendText = lessThanText.replace('%s', days.orange).replace('%d', machineCount.green) data.push(machineCount.green); legend.push(legendText); colors.push("#73d216"); href.push(urlRedirect + "&group=green&days=" + days.orange); } if (machineCount.orange) { var legendText = moreThanText.replace('%s', days.orange).replace('%d', machineCount.orange) data.push(machineCount.orange); legend.push(legendText); colors.push("#ff9c00"); href.push(urlRedirect + "&group=orange&days=" + days.orange); } if (machineCount.red) { var legendText = moreThanText.replace('%s', days.red).replace('%d', machineCount.red) data.push(machineCount.red); legend.push(legendText); colors.push("#ef2929"); href.push(urlRedirect + "&group=red&days=" + days.red); } // get data percentage values for pie chart generation data = getPercentageData(data); // put percentage values in legend for (var i = 0; i < data.length; i++) { legend[i] = legend[i].replace('%percent', data[i]); } var pie = r.piechart(x, y, radius, data, {legend: legend, legendpos: "south", colors: colors, href: href}); pie.hover(function () { this.sector.stop(); this.sector.animate({ transform: 's1.1 1.1 ' + this.cx + ' ' + this.cy }, 800, "elastic"); if (this.label) { this.label[0].stop(); this.label[0].attr({ r: 7.5 }); this.label[1].attr({ "font-weight": 800 }); } }, function () { this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 800, "elastic"); if (this.label) { this.label[0].animate({ r: 5 }, 500, "bounce"); this.label[1].attr({ "font-weight": 400 }); } }); </script> INVENTORY; }
function display_content() { $result = getMachineNumberByState(); $count = $result['count']; $days = $result['days']; $jsonCount = json_encode($count); $jsonDays = json_encode($days); $createGroupText = json_encode(_T("Create a group", "inventory")); $lessThanText = json_encode(_T("< %s days: %percent% (%d)", "inventory")); $moreThanText = json_encode(_T("> %s days: %percent% (%d)", "inventory")); $urlRedirect = json_encode(urlStrRedirect("inventory/inventory/createStaticGroup")); print _T("Latest Inventory Date", "inventory"); echo <<<INVENTORY <div id="inventory-graphs"></div> <script type="text/javascript"> var machineCount = {$jsonCount}, days = {$jsonDays}, lessThanText = {$lessThanText}, moreThanText = {$moreThanText}, createGroupText = {$createGroupText}, urlRedirect = {$urlRedirect}; var data = []; var legend = []; var colors = []; var href = []; if (machineCount.green) { var legendText = lessThanText.replace('%s', days.orange).replace('%d', machineCount.green) data.push(machineCount.green); legend.push(legendText); colors.push("000-#6AB520-#73d216"); href.push(urlRedirect + "&group=green&days=" + days.orange); } if (machineCount.orange) { var legendText = moreThanText.replace('%s', days.orange).replace('%d', machineCount.orange) data.push(machineCount.orange); legend.push(legendText); colors.push("000-#DA5324-#f3602c"); href.push(urlRedirect + "&group=orange&days=" + days.orange); } if (machineCount.red) { var legendText = moreThanText.replace('%s', days.red).replace('%d', machineCount.red) data.push(machineCount.red); legend.push(legendText); colors.push("000-#CD1515-#ef2929"); href.push(urlRedirect + "&group=red&days=" + days.red); } // get data percentage values for bar chart generation data = getPercentageData(data, 'bar'); // put percentage values in legend for (var i = 0; i < data.length; i++) { legend[i] = legend[i].replace('%percent', data[i]); } var r = Raphael("inventory-graphs", 200, 50); fin = function () { }, fout = function () { }, txtattr = { font: "12px sans-serif" }; r.hbarchart(0, 10, 200, 30, data, { type: 'round', stacked: true, colors: colors }).hover(fin, fout); \$('inventory-graphs').insert('<ul>'); for (var i = 0; i < legend.length; i++) { \$('inventory-graphs').insert( '<li style="color: ' + colors[i].split('-')[2] + '"><span style="color: #000">' + legend[i] + '<a href="' + href[i] + '"><img title="' + createGroupText + '" style="height: 10px; padding-left: 3px;" src="img/machines/icn_machinesList.gif" /></a></span></li>' ); } \$('inventory-graphs').insert('</ul>'); </script> <style type="text/css"> #inventory-graphs li { list-style: none; font-size: 13px; } #inventory-graphs li:before { content: "•"; font-size: 20px; vertical-align: bottom; line-height: 16px; margin-right: 3px; } </style> INVENTORY; }