1<?php 2 3/** 4 * Observium 5 * 6 * This file is part of Observium. 7 * 8 * @package observium 9 * @subpackage web 10 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 11 * 12 */ 13 14// These functions are used to generate our boxes. It's probably easier to put this into functions. 15 16function generate_box_open($args = array()) 17{ 18 // r($args); 19 20 $return = '<div '; 21 if (isset($args['id'])) { $return .= 'id="' . $args['id'] . '" '; } 22 23 $return .= 'class="' . OBS_CLASS_BOX . ($args['box-class'] ? ' '.$args['box-class'] : '') . '" '.($args['box-style'] ? 'style="'.$args['box-style'].'"' : ''). '>' . PHP_EOL; 24 25 if (isset($args['title'])) 26 { 27 $return .= ' <div class="box-header' . ($args['header-border'] ? ' with-border' : '') . '">'.PHP_EOL; 28 if(isset($args['url'])) { $return .= '<a href="'.$args['url'].'">'; } 29 if(isset($args['icon'])) { $return .= '<i class="'.$args['icon'].'"></i>'; } 30 $return .= '<' . (isset($args['title-element']) ? $args['title-element'] : 'h3').' class="box-title"'; 31 $return .= (isset($args['title-style']) ? ' style="'.$args['title-style'].'"' : ''); 32 $return .= '>'; 33 $return .= $args['title'].'</' . (isset($args['title-element']) ? $args['title-element'] : 'h3').'>'.PHP_EOL; 34 if(isset($args['url'])) { $return .= '</a>'; } 35 36 if (isset($args['header-controls']) && is_array($args['header-controls']['controls'])) 37 { 38 $return .= ' <div class="box-tools pull-right">'; 39 40 foreach($args['header-controls']['controls'] as $control) 41 { 42 if (isset($control['anchor']) && $control['anchor'] == TRUE) 43 { 44 $return .= ' <a role="button"'; 45 } else { 46 $return .= '<button type="button"'; 47 } 48 if (isset($control['url']) && strlen($control['url']) && $control['url'] != '#') 49 { 50 $return .= ' href="'.$control['url'].'"'; 51 } else { 52 //$return .= ' onclick="return false;"'; 53 } 54 55 $return .= ' class="btn btn-box-tool'; 56 if (isset($control['class'])) { $return .= ' '.$control['class']; } 57 $return .= '"'; 58 59 if (isset($control['data'])) { $return .= ' '.$control['data']; } 60 $return .= '>'; 61 62 if (isset($control['icon'])) { $return .= '<i class="'.$control['icon'].'"></i> '; } 63 if (isset($control['text'])) { $return .= $control['text']; } 64 65 if (isset($control['anchor']) && $control['anchor'] == TRUE) 66 { 67 $return .= '</a>'; 68 } else { 69 $return .= '</button>'; 70 } 71 } 72 73 $return .= ' </div>'; 74 } 75 $return .= ' </div>'.PHP_EOL; 76 } 77 78 $return .= ' <div class="box-body'.($args['padding'] ? '' : ' no-padding').'"'; 79 if (isset($args['body-style'])) 80 { 81 $return .= ' style="'.$args['body-style'].'"'; 82 } 83 $return .= '>'.PHP_EOL; 84 return $return; 85 86} 87 88function generate_box_close($args = array()) 89{ 90 $return = ' </div>' . PHP_EOL; 91 92 if(isset($args['footer_content'])) 93 { 94 $return .= ' <div class="box-footer'; 95 if(isset($args['footer_nopadding'])) { $return .= ' no-padding'; } 96 $return .= '">'; 97 $return .= $args['footer_content']; 98 $return .= ' </div>' . PHP_EOL; 99 } 100 101 $return .= '</div>' . PHP_EOL; 102 return $return; 103} 104 105// DOCME needs phpdoc block 106function print_graph_row_port($graph_array, $port) 107{ 108 109 global $config; 110 111 $graph_array['to'] = $config['time']['now']; 112 $graph_array['id'] = $port['port_id']; 113 114 print_graph_row($graph_array); 115} 116 117function generate_graph_summary_row($graph_summary_array, $state_marker = FALSE) 118{ 119 120 global $config; 121 122 $graph_array = $graph_summary_array; 123 124 unset($graph_array['types']); 125 126 if ($_SESSION['widescreen']) 127 { 128 if ($_SESSION['big_graphs']) 129 { 130 if (!$graph_array['height']) { $graph_array['height'] = "110"; } 131 if (!$graph_array['width']) { $graph_array['width'] = "372"; } 132 $limit = 4; 133 } else { 134 if (!$graph_array['height']) { $graph_array['height'] = "110"; } 135 if (!$graph_array['width']) { $graph_array['width'] = "287"; } 136 $limit = 5; 137 } 138 } else { 139 if ($_SESSION['big_graphs']) 140 { 141 if (!$graph_array['height']) { $graph_array['height'] = "100"; } 142 if (!$graph_array['width']) { $graph_array['width'] = "323"; } 143 $limit = 3; 144 } else { 145 if (!$graph_array['height']) { $graph_array['height'] = "100"; } 146 if (!$graph_array['width']) { $graph_array['width'] = "228"; } 147 $limit = 4; 148 } 149 } 150 151 if(!isset($graph_summary_array['period'])) { $graph_summary_array['period'] = "day"; } 152 if($state_marker) { $graph_array['width'] -= 2; } 153 $graph_array['to'] = $config['time']['now']; 154 $graph_array['from'] = $config['time'][$graph_summary_array['period']]; 155 156 $graph_rows = array(); 157 foreach ($graph_summary_array['types'] as $graph_type) 158 { 159 160// FIX THIS LATER :DDDD 161// $hide_lg = $period[0] === '!'; 162// if ($hide_lg) 163// { 164// $period = substr($period, 1); 165// } 166 167 168 $graph_array['type'] = $graph_type; 169 170 preg_match('/^(?P<type>[a-z0-9A-Z-]+)_(?P<subtype>[a-z0-9A-Z-_]+)/', $graph_type, $type_parts); 171 if (isset($config['graph_types'][$type_parts['type']][$type_parts['subtype']]['descr'])) 172 { 173 $descr = $config['graph_types'][$type_parts['type']][$type_parts['subtype']]['descr']; 174 } else { 175 $descr = nicecase($graph_type); 176 } 177 178 $graph_array_zoom = $graph_array; 179 $graph_array_zoom['height'] = "175"; 180 $graph_array_zoom['width'] = "600"; 181 unset($graph_array_zoom['legend']); 182 183 $link_array = $graph_array; 184 $link_array['page'] = "graphs"; 185 unset($link_array['height'], $link_array['width']); 186 $link = generate_url($link_array); 187 188 $popup_contents = '<h3>'.$descr.'</h3>'; 189 $popup_contents .= generate_graph_tag($graph_array_zoom); 190 191 $graph_link = overlib_link($link, generate_graph_tag($graph_array), $popup_contents, NULL); 192 193// if ($hide_lg) 194// { 195 // Hide this graph on lg/xl screen since it not fit to single row (on xs always visible, since here multirow) 196// $graph_link = '<div class="visible-xs-inline visible-lg-inline visible-xl-inline">' . $graph_link . '</div>'; 197// } 198 if(count($graph_rows) < $limit) { 199 $graph_rows[] = $graph_link; 200 } 201 202 } 203 204 return implode(PHP_EOL, $graph_rows); 205} 206 207 208// DOCME needs phpdoc block 209function generate_graph_row($graph_array, $state_marker = FALSE) 210{ 211 global $config; 212 213 if ($_SESSION['widescreen']) 214 { 215 if ($_SESSION['big_graphs']) 216 { 217 if (!$graph_array['height']) { $graph_array['height'] = "110"; } 218 if (!$graph_array['width']) { $graph_array['width'] = "372"; } 219 $periods = array('day', 'week', 'month', 'year'); 220 } else { 221 if (!$graph_array['height']) { $graph_array['height'] = "110"; } 222 if (!$graph_array['width']) { $graph_array['width'] = "287"; } 223 $periods = array('day', 'week', 'month', 'year', 'twoyear'); 224 } 225 } else { 226 if ($_SESSION['big_graphs']) 227 { 228 if (!$graph_array['height']) { $graph_array['height'] = "100"; } 229 if (!$graph_array['width']) { $graph_array['width'] = "323"; } 230 $periods = array('day', 'week', '!month'); 231 } else { 232 if (!$graph_array['height']) { $graph_array['height'] = "100"; } 233 if (!$graph_array['width']) { $graph_array['width'] = "228"; } 234 $periods = array('day', 'week', 'month', '!year'); 235 } 236 } 237 238 if ($graph_array['shrink']) { $graph_array['width'] = $graph_array['width'] - $graph_array['shrink']; } 239 240 // If we're printing the row inside a table cell with "state-marker", we need to make the graphs a tiny bit smaller to fit 241 if($state_marker) { $graph_array['width'] -= 2; } 242 243 $graph_array['to'] = $config['time']['now']; 244 245 $graph_rows = array(); 246 foreach ($periods as $period) 247 { 248 $hide_lg = $period[0] === '!'; 249 if ($hide_lg) 250 { 251 $period = substr($period, 1); 252 } 253 $graph_array['from'] = $config['time'][$period]; 254 $graph_array_zoom = $graph_array; 255 $graph_array_zoom['height'] = "175"; 256 $graph_array_zoom['width'] = "600"; 257 unset($graph_array_zoom['legend']); 258 259 $link_array = $graph_array; 260 $link_array['page'] = "graphs"; 261 unset($link_array['height'], $link_array['width']); 262 $link = generate_url($link_array); 263 264 $graph_link = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL); 265 if ($hide_lg) 266 { 267 // Hide this graph on lg/xl screen since it not fit to single row (on xs always visible, since here multirow) 268 $graph_link = '<div class="visible-xs-inline visible-lg-inline visible-xl-inline">' . $graph_link . '</div>'; 269 } 270 $graph_rows[] = $graph_link; 271 } 272 273 return implode(PHP_EOL, $graph_rows); 274} 275 276function print_graph_row($graph_array, $state_marker = FALSE) 277{ 278 echo(generate_graph_row($graph_array, $state_marker)); 279} 280 281function print_graph_summary_row($graph_array, $state_marker = FALSE) 282{ 283 echo(generate_graph_summary_row($graph_array, $state_marker)); 284} 285 286 287// EOF 288