1<?php 2 abstract class graph_controller extends controller { 3 protected $graphs = array(); 4 5 private function show_graphs() { 6 $filter = new filter($this->db, $this->output, $this->user); 7 $filter->to_output($this->model->table, $this->model->hostnames, $this->model->hours); 8 9 $begin = date("Y-m-d", strtotime("-".(MONITOR_DAYS - 1)." days")); 10 $end = date("Y-m-d"); 11 12 if (($statistics = $this->model->get_statistics($begin, $end, $filter)) === false) { 13 $this->output->add_tag("result", "Database error."); 14 return; 15 } 16 17 foreach ($this->graphs as $key => $label) { 18 $graph = new graph($this->output); 19 $graph->title = $label; 20 $graph->width = 960; 21 $graph->height = $this->output->mobile ? GRAPH_HEIGHT_MOBILE : GRAPH_HEIGHT; 22 23 foreach ($statistics as $day => $record) { 24 $timestamp = strtotime($day); 25 $day = date("l j F", $timestamp); 26 $class = date("N", $timestamp) > 5 ? "weekend" : "week"; 27 $link = sprintf("/%s/%s/%s", $this->page->page, $key, date("Y-m-d", $timestamp)); 28 29 $graph->add_bar($day, $record[$key], $class, $link); 30 } 31 32 $graph->to_output(); 33 unset($graph); 34 } 35 } 36 37 private function show_day_information($type, $date) { 38 $filter = new filter($this->db, $this->output, $this->user); 39 $filter->to_output($this->model->table, $this->model->hostnames, false); 40 41 if (($stats = $this->model->get_day_statistics($type, $date, $filter)) === false) { 42 $this->output->add_tag("result", "Database error."); 43 return false; 44 } 45 46 $graph = new graph($this->output); 47 $graph->title = $this->graphs[$type]." for ".date("l j F Y", strtotime($date)); 48 $graph->width = 960; 49 $graph->height = $this->output->mobile ? GRAPH_HEIGHT_MOBILE : GRAPH_HEIGHT; 50 51 foreach ($stats as $hour => $count) { 52 $graph->add_bar("Hour ".$hour, $count, "hour"); 53 } 54 55 $graph->to_output(); 56 57 if (($stats = $this->model->get_day_information($type, $date, $filter)) === false) { 58 $this->output->add_tag("result", "Database error."); 59 return false; 60 } 61 62 $this->output->open_tag("day", array( 63 "hostnames" => show_boolean($this->model->hostnames), 64 "type" => $type, 65 "label" => $this->graphs[$type], 66 "yesterday" => date("Y-m-d", strtotime($date." -1 day")), 67 "tomorrow" => date("Y-m-d", strtotime($date." +1 day")))); 68 69 foreach ($stats as $stat) { 70 if (($type == "requests") || ($type == "bytes_sent")) { 71 $stat["count"] = $this->model->readable_number($stat["count"]); 72 } 73 74 $this->output->record($stat, "stat"); 75 } 76 77 $this->output->close_tag(); 78 } 79 80 public function execute() { 81 $this->output->add_css("banshee/graphs.css"); 82 $this->output->add_css("banshee/filter.css"); 83 84 if ((in_array($this->page->pathinfo[1], array_keys($this->graphs)) == false) || (valid_date($this->page->pathinfo[2]) == false)) { 85 $this->show_graphs(); 86 } else { 87 $this->show_day_information($this->page->pathinfo[1], $this->page->pathinfo[2]); 88 } 89 } 90 } 91?> 92