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