From 1a076098050969d217f7abe8ec2102719fcba21d Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Sat, 5 Dec 2009 20:23:25 +0100 Subject: load plugins on the host page via ajax --- ajax.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ host.php | 11 +++++++---- inc/html.inc.php | 1 + layout/style.css | 4 ++++ plugin.php | 16 ++++++++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 ajax.js create mode 100644 plugin.php diff --git a/ajax.js b/ajax.js new file mode 100644 index 0000000..7b7bec3 --- /dev/null +++ b/ajax.js @@ -0,0 +1,47 @@ +function getP(host, plugin) { + getData(host, plugin, 'load'); +} + +function rmP(host, plugin) { + getData(host, plugin, 'del'); +} + +var xmlHttp + +function getData(obj, id, action) { + xmlHttp=GetXmlHttpObject(); + if (xmlHttp==null) { + alert ("Your browser does not support AJAX!"); + return; + } + + var url="plugin.php"; + url=url+"?h="+obj+"&p="+id+"&a="+action; + xmlHttp.onreadystatechange=function(){setData(id)} + xmlHttp.open("GET",url,true); + xmlHttp.send(null); +} + +function setData(obj) { + if (xmlHttp.readyState==4) { + div = document.getElementById(obj); + + div.innerHTML=xmlHttp.responseText; + } +} + +function GetXmlHttpObject() { + var xmlHttp=null; + try { + // Firefox, Opera 8.0+, Safari + xmlHttp=new XMLHttpRequest(); + } catch (e) { + // Internet Explorer + try { + xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + } + return xmlHttp; +} diff --git a/host.php b/host.php index 3bf3698..17cb499 100644 --- a/host.php +++ b/host.php @@ -21,21 +21,24 @@ if(!$plugins) { # first the ones defined in overview foreach($CONFIG['overview'] as $plugin) { if (in_array($plugin, $plugins)) { - printf("

\"[-]\" %s

\n", $CONFIG['weburl'], $plugin); + printf('
'."\n", $plugin); + printf("

\"[-]\" %s

\n", $host, $plugin, $CONFIG['weburl'], $plugin); graphs_from_plugin($host, $plugin); + print "
\n"; } } # other plugins foreach($plugins as $plugin) { if (!in_array($plugin, $CONFIG['overview'])) { - $url = sprintf('%s'."\n", $CONFIG['weburl'], $host, $plugin, $plugin); + printf('
'."\n", $plugin); if ($splugin == $plugin) { - printf("

\"[-]\" %s

\n", $CONFIG['weburl'], $url); + printf("

\"[-]\" %s

\n", $host, $plugin, $CONFIG['weburl'], $plugin); graphs_from_plugin($host, $plugin); } else { - printf("

\"[+]\" %s

\n", $CONFIG['weburl'], $url); + printf("

\"[+]\" %s

\n", $host, $plugin, $CONFIG['weburl'], $plugin); } + print "
\n"; } } diff --git a/inc/html.inc.php b/inc/html.inc.php index 09da518..b1cb80f 100644 --- a/inc/html.inc.php +++ b/inc/html.inc.php @@ -16,6 +16,7 @@ function html_start() { CGP{$path} + diff --git a/layout/style.css b/layout/style.css index 3b61a68..2e2003e 100644 --- a/layout/style.css +++ b/layout/style.css @@ -74,6 +74,10 @@ hr { border-top: 1px solid #000; } +.point { + cursor: pointer; +} + .small { font-size: 0.7em; } diff --git a/plugin.php b/plugin.php new file mode 100644 index 0000000..036dbb5 --- /dev/null +++ b/plugin.php @@ -0,0 +1,16 @@ +\"[+]\" %s\n", $host, $plugin, $CONFIG['weburl'], $plugin); +} else { + printf("

\"[-]\" %s

\n", $host, $plugin, $CONFIG['weburl'], $plugin); + graphs_from_plugin($host, $plugin); +} + +?> -- cgit v1.1