[gosa.git] / gosa-core / plugins / generic / statistics / chartClasses / class_passwordChangeChart.inc
1 <?php
3 class passwordChangeChart extends statChart
4 {
5 protected $title = 'Password changes';
6 protected $current_action = "";
8 function __construct(&$config)
9 {
10 parent::__construct($config);
11 $this->graphName = get_class();
12 }
15 /*! \brief Generates the line-graph which displays the plugin usage over time.
16 */
17 function render()
18 {
19 $lineMax = 10;
20 $gData = $this->graphData;
21 $dataSet = new pData;
22 $seriesCnt = 0;
24 $dataBase = $gData['usedPasswordHashes'];
26 foreach($dataBase as $category => $entriesPerDate){
27 if(empty($category) || in_array_strict($category, $this->skipSeries)) continue;
29 // Add results to our data set.
30 $dataSet->AddPoint($entriesPerDate, $category);
31 $dataSet->SetSerieName($this->getCategoryTranslation($category), $category);
32 $dataSet->AddSerie($category);
34 // Detect maximum value, to adjust the Y-Axis
35 $tmpMax = max($entriesPerDate);
36 if($tmpMax > $lineMax) $lineMax = $tmpMax;
37 $seriesCnt ++;
38 }
40 // Keep a list of all selecteable data-series, to allow the user to disable
41 // or enable series on demand.
42 $this->seriesList = array();
43 foreach($dataBase as $key => $data){
44 $this->seriesList[$key] = $this->getCategoryTranslation($key);
45 }
47 // Add timeline
48 $dataSet->AddPoint($gData['dates'], 'date');
49 $dataSet->SetAbsciseLabelSerie('date');
51 // Read graph from cache?
52 $pCache = new pCache($this->cachePath);
53 if($this->enableCaching && $pCache->IsInCache(get_class(),$dataSet->GetData())){
54 $filename = $pCache->GetHash(get_class(),$dataSet->GetData());
55 $filename = '/var/spool/gosa/'.$filename;
56 if(file_exists($filename) && is_readable($filename)){
57 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
58 session::set('statistics::graphFile'.$this->graphID,$filename);
59 return;
60 }
61 }
63 $chart = new pChart(900,230);
64 $chart->setFixedScale(0,$lineMax);
65 $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);
66 $chart->setGraphArea(50,28,630,200);
67 $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
68 $chart->drawRoundedRectangle(5,5,695,225,5,230,230,230);
69 $chart->drawGraphArea(255,255,255,TRUE);
70 $chart->drawGrid(4,TRUE,200,200,200,50);
71 $chart->drawTreshold(0,143,55,72,TRUE,TRUE);
72 $chart->drawTitle(50,22,_($this->title),50,50,50,585);
73 $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, TRUE);
75 // Only draw this graph if we've at least one series to draw!
76 if($seriesCnt){
77 $chart->drawFilledLineGraph($dataSet->GetData(),$dataSet->GetDataDescription(),50,TRUE);
78 #$chart->drawBarGraph($dataSet->GetData(),$dataSet->GetDataDescription(),TRUE);
79 #$chart->drawStackedBarGraph($dataSet->GetData(),$dataSet->GetDataDescription(),TRUE);
80 $chart->drawLegend(720,0,$dataSet->GetDataDescription(),255,255,255);
81 }
83 // Generate new and unique graph id
84 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
85 $file = '/tmp/graph_'.$this->graphID;
86 $chart->Render($file);
87 session::set('statistics::graphFile'.$this->graphID,$file);
88 $pCache->WriteToCache(get_class(),$dataSet->GetData(),$chart);
90 return;
91 }
92 }
93 ?>