From 9750afa08db705a76853fe94578cf54e8042cbb9 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 5 Aug 2010 10:14:20 +0000 Subject: [PATCH] Updated RPC handling of the stats plugin git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19366 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../generic/statistics/class_statistics.inc | 68 ++++++++++--------- .../plugins/generic/statistics/statistics.tpl | 45 +++++++----- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc index f925ea45d..842985a41 100644 --- a/gosa-core/plugins/generic/statistics/class_statistics.inc +++ b/gosa-core/plugins/generic/statistics/class_statistics.inc @@ -10,35 +10,49 @@ class statistics extends plugin var $receivedStats = array(); + var $rpcHandle = NULL; + + function __construct($config) { plugin::plugin($config, NULL); + // First try to retrieve values via RPC + $this->rpcConfigured = FALSE; + if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ + $this->rpcConfigured = TRUE; + $this->rpcHandle = $this->config->getRpcHandle( + "http://10.3.64.59:4000", + "65717fe6-9e3e-11df-b010-5452005f1250", + "WyukwauWoid2", + TRUE); + } } function execute() { + $smarty = get_smarty(); + // Do not render anything if we are not prepared to send and receive data via rpc. + $smarty->assign("rpcConfigured", $this->rpcConfigured); + if(!$this->rpcConfigured || !$this->rpcHandle){ + $smarty->assign("validRpcHandle", FALSE); + return($smarty->fetch(get_template_path('statistics.tpl', TRUE))); + } - if(isset($_POST['transmitStatistics'])){ - - // First try to retrieve values via RPC - if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ - $tmp = stats::dumpTables(); - $dump = array(); - foreach($tmp as $entry){ - $dump[] = array_values($entry); - } - $rpc = $this->config->getRpcHandle( - "http://10.3.64.59:4000", - "65717fe6-9e3e-11df-b010-5452005f1250", - "WyukwauWoid2", - TRUE); - $rpc->updateInstanceStatus($dump); - if(!$rpc->success()){ - msg_dialog::display(_("Error"),msgPool::rpcError($rpc->get_error()),ERROR_DIALOG); - } + $smarty->assign("validRpcHandle", TRUE); + if(isset($_POST['transmitStatistics'])){ + $tmp = stats::dumpTables(); + $dump = array(); + foreach($tmp as $entry){ + $dump[] = array_values($entry); + } + $res = $this->rpcHandle->updateInstanceStatus($dump); + if(!$this->rpcHandle->success()){ + msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); + }else{ + echo $res." Entries inserted"; } } @@ -47,14 +61,9 @@ class statistics extends plugin // First try to retrieve values via RPC if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){ - $rpc = $this->config->getRpcHandle( - "http://10.3.64.59:4000", - "65717fe6-9e3e-11df-b010-5452005f1250", - "WyukwauWoid2", - TRUE); - $res = $rpc->getInstanceStats(); - if(!$rpc->success()){ - msg_dialog::display(_("Error"),msgPool::rpcError($rpc->get_error()),ERROR_DIALOG); + $res = $this->rpcHandle->getInstanceStats(); + if(!$this->rpcHandle->success()){ + msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG); } $all = array_sum($res['category_count']); @@ -69,12 +78,7 @@ class statistics extends plugin } - - - $smarty = get_smarty(); - $smarty->assign("receivedStats",$this->receivedStats); - - + $smarty->assign("receivedStats",$this->receivedStats); return($smarty->fetch(get_template_path('statistics.tpl', TRUE))); } diff --git a/gosa-core/plugins/generic/statistics/statistics.tpl b/gosa-core/plugins/generic/statistics/statistics.tpl index 7d1028293..44df1208a 100644 --- a/gosa-core/plugins/generic/statistics/statistics.tpl +++ b/gosa-core/plugins/generic/statistics/statistics.tpl @@ -1,19 +1,30 @@ -

{t}Transmit daliy stats{/t} - - - - -{if $receivedStats} -

{t}Transmit daliy stats{/t}

- - {foreach from=$receivedStats key=key item=item} - - - - - {/foreach} -
{$key}{$item}
-{/if} +

{t}Usage statistics{/t}

+ +{if !$rpcConfigured} + + {t}This feature is disabled. To enable it you can use the GOsa properties plugin, just activate the remote procedure call (RPC) configuration flags.{/t} + +{else if !$validRpcHandle} + + {t}Communication with the GOsa-backend failed. Please check the rpc configuration!{/t} -
+{else} + + + +
+ + {if $receivedStats} +

{t}Transmit daliy stats{/t}

+ + {foreach from=$receivedStats key=key item=item} + + + + + {/foreach} +
{$key}{$item}
+ {/if} + +{/if} -- 2.30.2