842985a416868a7187dff7ab364ba8f17f0c36e5
1 <?php
3 class statistics extends plugin
4 {
5 var $plHeadline = 'Statistics';
6 var $plDescription = 'GOsa usage statistics';
7 var $plShortIcon = 'statistics.png';
8 var $plIcon = 'plugin.png';
10 var $receivedStats = array();
13 var $rpcHandle = NULL;
16 function __construct($config)
17 {
18 plugin::plugin($config, NULL);
20 // First try to retrieve values via RPC
21 $this->rpcConfigured = FALSE;
22 if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){
23 $this->rpcConfigured = TRUE;
24 $this->rpcHandle = $this->config->getRpcHandle(
25 "http://10.3.64.59:4000",
26 "65717fe6-9e3e-11df-b010-5452005f1250",
27 "WyukwauWoid2",
28 TRUE);
29 }
30 }
32 function execute()
33 {
34 $smarty = get_smarty();
36 // Do not render anything if we are not prepared to send and receive data via rpc.
37 $smarty->assign("rpcConfigured", $this->rpcConfigured);
38 if(!$this->rpcConfigured || !$this->rpcHandle){
39 $smarty->assign("validRpcHandle", FALSE);
40 return($smarty->fetch(get_template_path('statistics.tpl', TRUE)));
41 }
44 $smarty->assign("validRpcHandle", TRUE);
45 if(isset($_POST['transmitStatistics'])){
46 $tmp = stats::dumpTables();
47 $dump = array();
48 foreach($tmp as $entry){
49 $dump[] = array_values($entry);
50 }
51 $res = $this->rpcHandle->updateInstanceStatus($dump);
52 if(!$this->rpcHandle->success()){
53 msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG);
54 }else{
55 echo $res." Entries inserted";
56 }
57 }
59 // Transmit daily statistics to GOsa-Server
60 if(isset($_POST['receiveStatistics'])){
62 // First try to retrieve values via RPC
63 if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){
64 $res = $this->rpcHandle->getInstanceStats();
65 if(!$this->rpcHandle->success()){
66 msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG);
67 }
69 $all = array_sum($res['category_count']);
70 $tmp = array();
71 $tmpRendered = array();
72 foreach($res['category_count'] as $category => $count){
73 $tmp[$category] = floor(($count / $all) * 10000) / 100;
74 $tmpRendered[$category] = progressbar($tmp[$category]);
75 }
76 $this->receivedStats = $tmpRendered;
77 }
78 }
81 $smarty->assign("receivedStats",$this->receivedStats);
82 return($smarty->fetch(get_template_path('statistics.tpl', TRUE)));
83 }
85 function check()
86 {
87 $messages = plugin::check();
88 return($messages);
89 }
91 function save_object()
92 {
93 plugin::save_object();
94 }
95 }
96 ?>