예제 #1
0
function print_sensor_table($vars)
{
    $sql = build_sensor_query($vars);
    $sensors = array();
    foreach (dbFetchRows($sql) as $sensor) {
        //if (isset($GLOBALS['cache']['devices']['id'][$sensor['device_id']]))
        //{
        $sensor['hostname'] = $GLOBALS['cache']['devices']['id'][$sensor['device_id']]['hostname'];
        $sensors[] = $sensor;
        //}
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'device':
            $sensors = array_sort_by($sensors, 'hostname', $sort_order, SORT_STRING);
            break;
        case 'descr':
            $sensors = array_sort_by($sensors, 'sensor_descr', $sort_order, SORT_STRING);
            break;
        case 'event':
            $sensors = array_sort_by($sensors, 'sensor_event', $sort_order, SORT_STRING);
            break;
        case 'value':
            $sensors = array_sort_by($sensors, 'sensor_value', $sort_order, SORT_STRING);
            break;
        case 'last_change':
            $sensors = array_sort_by($sensors, 'sensor_last_change', $sort_neg, SORT_NUMERIC);
            break;
        default:
            $sensors = array_sort_by($sensors, 'hostname', $sort_order, SORT_STRING, 'sensor_descr', $sort_order, SORT_STRING);
    }
    $sensors_count = count($sensors);
    // Pagination
    $pagination_html = pagination($vars, $sensors_count);
    echo $pagination_html;
    if ($vars['pageno']) {
        $sensors = array_chunk($sensors, $vars['pagesize']);
        $sensors = $sensors[$vars['pageno'] - 1];
    }
    // End Pagination
    echo generate_box_open();
    print_sensor_table_header($vars);
    foreach ($sensors as $sensor) {
        print_sensor_row($sensor, $vars);
    }
    echo "</tbody></table>";
    echo generate_box_close();
    echo $pagination_html;
}
예제 #2
0
                    // Some time sensor descriptions equals to entity name
                    $sensor['sensor_descr'] = nicecase($sensor['sensor_class']);
                }
                print_sensor_row($sensor, $vars);
            }
        }
        ?>
      </table>
<?php 
        echo generate_box_close();
    }
    // End for print bounds, unset this array
    unset($sensors_db['measured']);
}
foreach ($sensors_db as $sensor_type => $sensors) {
    if ($sensor_type == 'measured') {
        continue;
    }
    // Just be on the safe side
    if (count($sensors)) {
        $box_args = array('title' => nicecase($sensor_type), 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => $sensor_type)), 'icon' => $config['sensor_types'][$sensor_type]['icon']);
        echo generate_box_open($box_args);
        echo '<table class="table table-condensed table-striped">';
        foreach ($sensors as $sensor) {
            print_sensor_row($sensor, $vars);
        }
        echo "</table>";
        echo generate_box_close();
    }
}
// EOF