Code

Updated RPC handling of the stats plugin
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Aug 2010 10:14:20 +0000 (10:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Aug 2010 10:14:20 +0000 (10:14 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19366 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/statistics/class_statistics.inc
gosa-core/plugins/generic/statistics/statistics.tpl

index f925ea45def8a036a3c6cfac79a1514894e421c9..842985a416868a7187dff7ab364ba8f17f0c36e5 100644 (file)
@@ -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)));
     }
 
index 7d1028293f56a185f0a1a62f163a729c3944db9e..44df1208ad95283a03f6e8a8e2eaa3b5c860d955 100644 (file)
@@ -1,19 +1,30 @@
-<h3>{t}Transmit daliy stats{/t}
-
-<button name='transmitStatistics'>{t}Send{/t}</button>
-<button name='receiveStatistics'>{t}Receive{/t}</button>
-
-{if $receivedStats}
-    <h3>{t}Transmit daliy stats{/t}</h3>
-    <table summary="{t}Generated usage statistics{/t}">
-    {foreach from=$receivedStats key=key item=item}
-        <tr>
-            <td>{$key}</td>
-            <td>{$item}</td>
-        </tr>
-    {/foreach}
-    </table>
-{/if}
+<h3>{t}Usage statistics{/t}</h3>
+
+{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}
 
-<hr>
+{else}
 
+    <button name='transmitStatistics'>{t}Send{/t}</button>
+    <button name='receiveStatistics'>{t}Receive{/t}</button>
+
+    <hr>
+
+    {if $receivedStats}
+        <h3>{t}Transmit daliy stats{/t}</h3>
+        <table summary="{t}Generated usage statistics{/t}">
+        {foreach from=$receivedStats key=key item=item}
+            <tr>
+                <td>{$key}</td>
+                <td>{$item}</td>
+            </tr>
+        {/foreach}
+        </table>
+    {/if}
+
+{/if}