]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/backupjob-report.php
bacula-web: php code cleanup
[bacula/bacula] / gui / bacula-web / backupjob-report.php
1 <?php\r
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco                                              |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17   session_start();\r
18   include_once( 'config.inc.php' );
19 \r
20   $dbSql = new Bweb();\r
21 \r
22   $backupjob_name               = "";
23   $backupjob_bytes              = 0;
24   $backupjob_files              = 0;
25 \r
26   $days                                 = array();
27   $days_stored_bytes    = array();
28   $days_stored_files    = array();
29
30   // ===============================================================
31   // Get Backup Job name from GET or POST\r
32   // ===============================================================
33   if( isset( $_POST["backupjob_name"] ) )\r
34     $backupjob_name = $_POST["backupjob_name"];\r
35   elseif( isset( $_GET["backupjob_name"] ) )\r
36         $backupjob_name = $_GET["backupjob_name"];\r
37   else\r
38         die( "Please specify a backup job name " );\r
39 \r
40   // Generate Backup Job report period string
41   $backupjob_period = "From " . date( "Y-m-d", (NOW-WEEK) ) . " to " . date( "Y-m-d", NOW );
42   
43   // Calculate total bytes for this period
44   $backupjob_bytes = $dbSql->getStoredBytes( LAST_WEEK, NOW, $backupjob_name );
45   $backupjob_bytes = CUtils::Get_Human_Size( $backupjob_bytes );
46         
47   // Get the last 7 days interval (start and end)\r
48   for( $c = 6 ; $c >= 0 ; $c-- ) {\r
49           $today  = NOW - ($c * DAY);
50           $days[] = CTimeUtils::get_Day_Intervals($today);
51   }\r
52   
53   // ===============================================================
54   // Last 7 days stored Bytes graph\r
55   // ===============================================================  
56   $graph = new CGraph( "graph2.png" );
57 \r
58   foreach( $days as $day ) {
59         $stored_bytes            = $dbSql->getStoredBytes( $day['start'], $day['end'], $backupjob_name);
60         $stored_bytes            = CUtils::Get_Human_Size( $stored_bytes, 1, 'GB', false );
61         $days_stored_bytes[] = array( date("m-d", $day['start']), $stored_bytes );
62   }
63   
64   $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );\r
65   $graph->SetGraphSize( 400, 230 );\r
66   $graph->SetYTitle( "GB" );
67 \r
68   $graph->Render();\r
69   $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() ); 
70   \r
71   // ===============================================================
72   // Getting last 7 days stored files graph\r
73   // ===============================================================
74   $graph = new CGraph("graph3.png" );
75   \r
76   foreach( $days as $day )\r
77     array_push( $days_stored_files, $dbSql->GetStoredFilesByJob( $backupjob_name, $day['start'], $day['end'] ) );\r
78 \r
79   // Calculate total files for this period      \r
80   foreach( $days_stored_files as $day )\r
81         $backupjob_files += $day[1];\r
82   \r
83   $graph->SetData( $days_stored_files, 'bars', 'text-data' );\r
84   $graph->SetGraphSize( 400, 230 );\r
85   $graph->SetYTitle( "Files" );
86 \r
87   $graph->Render();\r
88   $dbSql->tpl->assign('graph_stored_files', $graph->Get_Image_file() );
89 \r
90   // Last 10 jobs\r
91   $query    = "SELECT JobId, Level, JobFiles, JobBytes, JobStatus, StartTime, EndTime, Name ";  
92   $query   .= "FROM Job ";\r
93   $query   .= "WHERE Name = '$backupjob_name' ";\r
94   $query   .= "ORDER BY EndTime DESC ";\r
95   $query   .= "LIMIT 10 ";\r
96   \r
97   $jobs         = array();\r
98   $joblevel = array( 'I' => 'Incr', 'D' => 'Diff', 'F' => 'Full' );\r
99   $result       = $dbSql->db_link->query( $query );\r
100   \r
101   if( ! PEAR::isError( $result ) )\r
102   {\r
103         while( $job = $result->fetchRow() )
104         {
105                 // Job level description
106                 $job['joblevel']        = $joblevel[ $job['level'] ];
107
108                 // Job execution execution time
109                 $job['elapsedtime'] = CTimeUtils::Get_Elapsed_Time( $job['starttime'], $job['endtime'] );
110
111                 // odd and even row
112                 if( count($jobs) % 2)
113                         $job['row_class'] = 'odd';
114                 // Job bytes in human format
115                 $job['jobbytes'] = CUtils::Get_Human_Size( $job['jobbytes'] );
116
117                 array_push( $jobs, $job);\r
118         }               
119   }else\r
120         $dbSql->TriggerDBError("Unable to get last jobs from catalog", $result);
121     \r
122   $dbSql->tpl->assign('jobs', $jobs );
123   $dbSql->tpl->assign('backupjob_name', $backupjob_name );
124   $dbSql->tpl->assign('backupjob_period', $backupjob_period );
125   $dbSql->tpl->assign('backupjob_bytes', $backupjob_bytes );
126   $dbSql->tpl->assign('backupjob_files', $backupjob_files );
127   \r
128   // Process and display the template \r
129   $dbSql->tpl->display('backupjob-report.tpl'); 
130   \r
131 ?>\r