]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
a9bcb72adf22c1880c6292d56f1df5bab6228c58
[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 $last24bytes = $dbSql->link->query("select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400")
42         or die ("Error query: 3");
43 $bytes_stored =& $dbSql->link->getOne("select SUM(VolBytes) from Media")
44         or die ("Error query: 4");
45
46 $smarty->assign('database_size', $dbSql->GetDbSize());
47 $smarty->assign('bytes_stored',$bytes_stored);
48
49 $tmp = $client->fetchRow();
50 $smarty->assign('clientes_totales',$tmp[0]);
51
52 $tmp = $last24bytes->fetchRow();
53 if ( empty($tmp[0]) ) {                                                                                                                 // No data for last 24, search last 48
54         $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" );
55         $smarty->assign('when',"yesterday");
56 }
57 $smarty->assign('bytes_totales',$tmp[0]);
58 $smarty->assign('total_jobs', $tmp[1]);
59
60 $tmp = $totalfiles->fetchRow();
61 $smarty->assign('files_totales',$tmp[0]);
62
63 $client->free();
64 $totalfiles->free();
65 $last24bytes->free();
66
67
68 // report_select.tpl & last_run_report.tpl
69 $res = $dbSql->link->query("select Name from Job group by Name");
70 $a_jobs = array();
71 while ( $tmp = $res->fetchRow() )
72         array_push($a_jobs, $tmp[0]);
73 $smarty->assign('total_name_jobs',$a_jobs);
74 $smarty->assign('time2',( (time())-2678400) );                                                                  // Current time - 1 month. <select> date
75 $res->free();
76
77 // volumes.tpl
78 $volumes = $dbSql->GetDataVolumes();                                                                                    // Obtain array with info
79 $pools = array_keys($volumes);                                                                                                  // Extract Pools
80 $smarty->assign('pools',$pools);        
81 $smarty->assign('volumes',$volumes);
82
83 // last_run_report.tpl
84 if ($mode == "Lite" && $_GET['Full_popup'] != "yes") {
85         $tmp = array();
86         $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'" )               
87                 or die ("Error: query at row 85");
88         $smarty->assign('status', $status->numRows());
89         if ( $status->numRows() ) {
90                 while ( $res = $status->fetchRow() )
91                         array_push($tmp, $res);
92                 $smarty->assign('errors_array',$tmp);
93         }
94         $status->free();
95         
96         // Total Elapsed Time. Only for single Job.
97         $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")
98                 or die ("Error at row 96");
99         while ( $res = $ret->fetchRow() ) {
100                 if ( $TotalElapsed < 1000000000 )                                                                               // Temporal "workaround" ;) Fix later
101                         $TotalElapsed += $res[0];
102         }
103         if ($TotalElapsed > 86400)                                                                                                      // More than 1 day!
104                 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
105         else
106                 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
107         $smarty->assign('TotalElapsed',$TotalElapsed);
108         $ret->free();
109 }
110 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
111         $tmp1 = array();
112         if ( $dbSql->driver == "mysql")
113                 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
114                                 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job 
115                                 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 
116                                 order by elapsed ";                                                                                                     // Full report array
117         if ( $dbSql->driver == "pgsql")
118                 $query = "select Job.EndTime::timestamp-Job.StartTime::timestamp as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 order by elapsed ";
119         $status = $dbSql->link->query($query)
120                 or die ("Error: query at row 118");
121         while ( $tmp = $status->fetchRow() ) {
122                 $tdate = explode (":",$tmp[0]);
123                 if ( $tdate[0] > 300000 )                                                                                               // Temporal "workaround" ;) Fix later
124                         $tmp[0] = "00:00:00";
125                 array_push($tmp1,$tmp);
126         }
127         
128         $smarty->assign('clients',$tmp1);
129 }  
130
131
132 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
133         $smarty->display('full_popup.tpl');
134 else
135         $smarty->display('index.tpl');
136 ?>