1 <?php
3 class statChart{
5 // Graph data
6 var $statisticData = array(); // Via rpc received stats
8 // Font used in graphs
9 var $font = "./themes/default/fonts/LiberationSans-Regular.ttf";
10 var $graphData = array();
11 var $graphID = 0;
12 var $enableCaching = TRUE;
14 var $skipSeries = array();
16 var $graphName = 0;
18 var $seriesList = array();
20 function __construct(&$config,$gData = array())
21 {
22 $this->config = $config;
24 // Collect category translations
25 $this->catTranslations = array();
26 foreach($this->config->configRegistry->getListOfPlugins() as $plugin => $data){
27 if(isset($data['plCategory'])){
28 foreach($data['plCategory'] as $id => $name){
29 if(!is_numeric($id)){
30 $this->catTranslations[$id] = $name['description'];
31 }
32 }
33 }
34 }
35 }
38 function setGraphData($data)
39 {
40 $this->graphData = $data;
41 }
44 /*! \brief This method tries to translate category names.
45 * @param The category name to translate
46 * @return String The translated category names.
47 */
48 function getCategoryTranslation($name)
49 {
50 $ret ="";
52 // We do not have a category for systems directly, so we've to map all system types to 'System'.
53 // If we do not map to _(Systems) the graph legend will be half screen width.
54 if($name == "systems"){
55 return(_("Systems"));
56 }
58 // Walk through category names and try to find a translation.
59 $cat = trim($name);
60 if(isset($this->catTranslations[$cat])){
61 $cat = _($this->catTranslations[$cat]);
62 }elseif(!empty($cat)){
63 $cat = _($cat);
64 }
65 return($cat);
66 }
69 function getGraphID()
70 {
71 return($this->graphID);
72 }
74 function getSeriesList()
75 {
76 return($this->seriesList);
77 }
79 function getSeriesSelector()
80 {
81 $str = "<input type='hidden' name='{$this->graphName}_posted' value='1'>";
82 $list = $this->getSeriesList();
83 foreach($list as $key => $item){
84 $checked = (in_array($key, $this->skipSeries))? '': 'checked';
85 $str .= "<span style='padding-right:20px'>".
86 " <input type='checkbox' name='addSeries_{$this->graphName}_{$key}' value='1'".
87 " onClick=\"document.mainform.submit();\" ".
88 " {$checked}>{$item}".
89 " </span>";
90 }
91 return($str);
92 }
94 function save_object()
95 {
96 if(!isset($_POST["{$this->graphName}_posted"])) return;
98 // Get series to enable or disable
99 $this->skipSeries = array();
100 foreach($this->seriesList as $seriesName => $seriesDesc){
101 if(!isset($_POST["addSeries_{$this->graphName}_{$seriesName}"])){
102 $this->skipSeries[] = $seriesName;
103 }
104 }
105 }
106 }
107 ?>