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 $rpcHandle = NULL;
11 var $rpcConfigured = FALSE;
13 var $graphID_1 = 0;
15 function __construct($config)
16 {
17 plugin::plugin($config, NULL);
19 // First try to retrieve values via RPC
20 $this->rpcConfigured = FALSE;
21 if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){
22 $this->rpcConfigured = TRUE;
23 $this->rpcHandle = $this->config->getRpcHandle(
24 "http://10.3.64.59:4000",
25 "65717fe6-9e3e-11df-b010-5452005f1250",
26 "WyukwauWoid2",
27 TRUE);
28 }
29 }
31 function execute()
32 {
33 $smarty = get_smarty();
35 // Do not render anything if we are not prepared to send and receive data via rpc.
36 $smarty->assign("rpcConfigured", $this->rpcConfigured);
37 $smarty->assign("validRpcHandle", TRUE);
38 if(!$this->rpcConfigured || !$this->rpcHandle){
39 $smarty->assign("validRpcHandle", FALSE);
40 return($smarty->fetch(get_template_path('statistics.tpl', TRUE)));
41 }
43 // Send stats
44 if(isset($_POST['transmitStatistics'])){
45 $tmp = stats::dumpTables();
46 $dump = array();
47 foreach($tmp as $entry){
48 $dump[] = array_values($entry);
49 }
50 $res = $this->rpcHandle->updateInstanceStatus($dump);
51 if(!$this->rpcHandle->success()){
52 msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG);
53 }else{
54 echo $res." Entries inserted";
55 }
56 }
58 // Transmit daily statistics to GOsa-Server
59 if(isset($_POST['receiveStatistics'])){
61 // First try to retrieve values via RPC
62 if ($this->config->get_cfg_value("core","gosaRpcServer") != ""){
63 $res = $this->rpcHandle->getInstanceStats();
64 if(!$this->rpcHandle->success()){
65 msg_dialog::display(_("Error"),msgPool::rpcError($this->rpcHandle->get_error()),ERROR_DIALOG);
66 }
68 $all = array_sum($res['category_count']);
69 $data = array();
70 foreach($res['category_count'] as $category => $count){
71 $tmp[$category] = floor(($count / $all) * 10000) / 100;
72 $data[] = array($category, floor(($count / $all) * 10000) / 100);
73 }
76 $this->graphID_1 = preg_replace("/[^0-9]/","",microtime(TRUE));
77 $plot = new PHPlot(600,400);
78 $plot->SetImageBorderType('plain');
80 $plot->SetTitle("World Gold Production, 1990\n(1000s of Troy Ounces)");
81 $plot->SetPlotType('pie');
82 $plot->SetDataType('text-data-single');
83 $plot->SetDataValues($data);
85 foreach ($data as $row)
86 $plot->SetLegend(implode(': ', $row));
89 $plot->SetOutputFile('/tmp/graph_'.$this->graphID_1);
90 $plot->SetIsInline(TRUE);
91 $plot->DrawGraph();
93 session::set('statistics::graphFile'.$this->graphID_1,'/tmp/graph_'.$this->graphID_1);
94 }
95 }
97 $smarty->assign('graphID_1', $this->graphID_1);
98 return($smarty->fetch(get_template_path('statistics.tpl', TRUE)));
99 }
101 function check()
102 {
103 $messages = plugin::check();
104 return($messages);
105 }
107 function save_object()
108 {
109 plugin::save_object();
110 }
111 }
112 ?>