Code

Applied in_array strict patches from trunk
[gosa.git] / gosa-core / plugins / generic / statistics / chartClasses / class_statChart.inc
1 <?php
3 class statChart{
5     // Graph data 
6     protected $statisticData = array();       // Via rpc received stats
7     
8     // Font used in graphs
9     protected $font = "./themes/default/fonts/LiberationSans-Regular.ttf";
10     protected $graphData = array();    
11     protected $graphID = 0;
12     protected $enableCaching = TRUE;
13     protected $skipSeries = array();
14     protected $graphName = 0;
15     protected $seriesList = array();
17     protected $cachePath = "";
19     function __construct(&$config,$gData = array())
20     {
21         // Try to get the configured stats path to store image for caching reasons
22         $path = $config->get_cfg_value('core', 'statsDatabaseDirectory');
23         if(!empty($path)){
24             $this->cachePath = "{$path}/images/";
25         }else{
26             $this->cachePath = "/var/spool/gosa/stats/images/";
27         }
29         // Try to create the cache path
30         if(!is_dir($this->cachePath)){
31             @mkdir($this->cachePath);
32         }
34         $this->config = $config;
36         // Collect category translations
37         $this->catTranslations = array();
38         foreach($this->config->configRegistry->getListOfPlugins() as $plugin => $data){
39             if(isset($data['plCategory'])){
40                 foreach($data['plCategory'] as $id => $name){
41                     if(!is_numeric($id)){
42                         $this->catTranslations[$id] = $name['description'];
43                     }
44                 }
45             }
46         }
47     }
50     function getTitle()
51     {
52         return(_($this->title));
53     }    
56     function setGraphData($data)
57     {
58         $this->graphData = $data;
59     }
62     /*! \brief      This method tries to translate category names.
63      *  @param      The category name to translate
64      *  @return     String  The translated category names.
65      */
66     function getCategoryTranslation($name)
67     {
68         $ret ="";
70         // We do not have a category for systems directly, so we've to map all system types to 'System'.
71         // If we do not map to _(Systems) the graph legend will be half screen width.
72         if($name == "systems"){
73             return(_("Systems"));
74         }
76         // Walk through category names and try to find a translation.
77         $cat = trim($name);
78         if(isset($this->catTranslations[$cat])){
79             $cat = _($this->catTranslations[$cat]);
80         }elseif(!empty($cat)){
81             $cat = _($cat);
82         }
83         return($cat); 
84     }
87     function getGraphID()
88     {
89         return($this->graphID);
90     }
92     function getSeriesList()
93     {
94         return($this->seriesList);
95     }
97     function getGraphOptions()
98     {
99         return("");
100     }
102     function getSeriesSelector()
103     {
104         $str = "<input type='hidden' name='{$this->graphName}_posted' value='1'>";
105         $list = $this->getSeriesList();
106         foreach($list as $key => $item){
107             $checked = (in_array_strict($key, $this->skipSeries))? '': 'checked';
108             $str .= "<span style='padding-right:20px'>".
109                     "   <input id='addSeries_{$this->graphName}_{$key}' type='checkbox' ".
110                     "       name='addSeries_{$this->graphName}_{$key}' value='1'".
111                     "       onClick=\"document.mainform.submit();\" ".
112                     "       {$checked}><LABEL for='addSeries_{$this->graphName}_{$key}'>{$item}</LABEL>".
113                     "   </span>";
114         }
115         return($str);
116     }
118     function save_object()
119     {
120         if(!isset($_POST["{$this->graphName}_posted"])) return;
122         // Get series to enable or disable
123         $this->skipSeries = array();
124         foreach($this->seriesList as $seriesName => $seriesDesc){
125             if(!isset($_POST["addSeries_{$this->graphName}_{$seriesName}"])){
126                 $this->skipSeries[] = $seriesName;
127             }
128         }
129     }
131 ?>