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