]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
- Fixed mysql database size result. Reported by Roland Arendes
[bacula/bacula] / gui / bacula-web / index.php
1 <?
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004 Juan Luis Francés Jiménez                            |
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 // Last Err: 
18 require ("paths.php");
19 require($smarty_path."Smarty.class.php");
20 include "classes.inc";
21
22 $smarty = new Smarty;                                                                                                                   // Template engine
23 $dbSql = new Bweb();
24
25 //$smarty->compile_check = true;
26 //$smarty->debugging = true;
27 $smarty->template_dir = "./templates";
28 $smarty->compile_dir = "./templates_c";
29 $smarty->config_dir     = "./configs";
30 $smarty->config_load("bacula.conf");                                                                                    // Load config file
31 $mode = $smarty->get_config_vars("mode");                                                                               // Lite o Extend?
32
33 require("lang.php");
34
35
36 // generaldata.tpl & last_run_report.tpl (last24bytes)
37 $client = $dbSql->link->query("select count(*) from Client")
38         or die ("Error query: 1");
39 $totalfiles = $dbSql->link->query("select count(FilenameId) from Filename")
40         or die ("Error query: 2");
41 if ( $dbSql->driver == "mysql")
42   $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400")
43         or die ("Error query: 3");
44 if ( $dbSql->driver == "pgsql")
45   $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'")
46         or die ("Error query: 3");
47 $bytes_stored =& $dbSql->link->getOne("select SUM(VolBytes) from Media")
48         or die ("Error query: 4");
49
50 $smarty->assign('database_size', $dbSql->GetDbSize());
51 $smarty->assign('bytes_stored',$bytes_stored);
52
53 $tmp = $client->fetchRow();
54 $smarty->assign('clientes_totales',$tmp[0]);
55
56 $tmp = $last24bytes->fetchRow();
57 if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
58         if ( $dbSql->driver == "mysql" )
59           $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
60         if ( $dbSql->driver == "pgsql")
61           $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800" );
62         $smarty->assign('when',"yesterday");
63 }
64 $smarty->assign('bytes_totales',$tmp[0]);
65 $smarty->assign('total_jobs', $tmp[1]);
66
67 $tmp = $totalfiles->fetchRow();
68 $smarty->assign('files_totales',$tmp[0]);
69
70 $client->free();
71 $totalfiles->free();
72 $last24bytes->free();
73
74
75 // report_select.tpl & last_run_report.tpl
76 $res = $dbSql->link->query("select Name from Job group by Name");
77 $a_jobs = array();
78 while ( $tmp = $res->fetchRow() )
79         array_push($a_jobs, $tmp[0]);
80 $smarty->assign('total_name_jobs',$a_jobs);
81 $smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
82 $res->free();
83
84 // volumes.tpl
85 $volumes = $dbSql->GetDataVolumes();                                                                                    // Obtain array with info
86 $pools = array_keys($volumes);                                                                                                  // Extract Pools
87 $smarty->assign('pools',$pools);        
88 $smarty->assign('volumes',$volumes);
89
90 // last_run_report.tpl
91 if ($mode == "Lite" && $_GET['Full_popup'] != "yes") {
92         $tmp = array();
93         if ( $dbSql->driver == "mysql" )
94           $status = $dbSql->link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'" )               
95                 or die ("Error: query at row 95");
96         if ( $dbSql->driver == "pgsql" )
97           $status = $dbSql->link->query("select JobId,Name,EndTime,JobStatus from Job where EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'")
98                 or die ( "Error: query at row 98" );
99         $smarty->assign('status', $status->numRows());
100         if ( $status->numRows() ) {
101                 while ( $res = $status->fetchRow() )
102                         array_push($tmp, $res);
103                 $smarty->assign('errors_array',$tmp);
104         }
105         $status->free();
106         
107         // Total Elapsed Time. Only for single Job.
108         if ( $dbSql->driver == "mysql" )
109           $ret = $dbSql->link->query("select UNIX_TIMESTAMP(EndTime)-UNIX_TIMESTAMP(StartTime) as elapsed from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-84600")
110                 or die ("Error at row 110");
111         if ( $dbSql->driver == "pgsql" )
112           $ret = $dbSql->link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
113                 or die ("Error at row 113");
114         while ( $res = $ret->fetchRow() ) {
115                 if ( $TotalElapsed < 1000000000 )                                                                               // Temporal "workaround" ;) Fix later
116                         $TotalElapsed += $res[0];
117         }
118         if ($TotalElapsed > 86400)                                                                                                      // More than 1 day!
119                 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
120         else
121                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
122         $smarty->assign('TotalElapsed',$TotalElapsed);
123         $ret->free();
124 }
125 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
126         $tmp1 = array();
127         if ( $dbSql->driver == "mysql")
128                 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
129                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job 
130                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 
131                                 order by elapsed ";                                                                                                     // Full report array
132         if ( $dbSql->driver == "pgsql")
133                 $query = "select Job.EndTime - Job.StartTime )
134                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
135                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
136                                 order by elapsed ";
137         $status = $dbSql->link->query($query)
138                 or die ("Error: query at row 138");
139         while ( $tmp = $status->fetchRow() ) {
140                 $tdate = explode (":",$tmp[0]);
141                 if ( $tdate[0] > 300000 )                                                                                               // Temporal "workaround" ;) Fix later
142                         $tmp[0] = "00:00:00";
143                 array_push($tmp1,$tmp);
144         }
145         
146         $smarty->assign('clients',$tmp1);
147 }  
148
149
150 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
151         $smarty->display('full_popup.tpl');
152 else
153         $smarty->display('index.tpl');
154 ?>