web: introduce a devices tab in the account section

This commit is contained in:
Bart Van Der Meerssche 2010-03-08 13:50:30 +00:00
parent 9f97afe4a2
commit 3d8636611e
2 changed files with 74 additions and 3 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
// //
// logger.admin.inc : callbacks for logger account and admin pages // logger.admin.inc : callbacks for logger account and admin pages
// Copyright (c) 2010 flukso.net // Copyright (c) 2010 flukso.net
@ -20,8 +21,66 @@
// $Id$ // $Id$
// //
/**
* Callback function for the user/x/devices page
*/
function _logger_account_devices() {
global $user;
$rows = array();
$result = db_query("SELECT serial, access, resets, uptime
FROM {logger_devices}
WHERE uid = %d
ORDER BY serial", $user->uid);
function unix_to_userlocaltime($unix) {
global $user;
$unix_local = gmdate('r', $unix + $user->timezone);
return substr($unix_local, 0, strlen($unix_local)-6);
}
function seconds_to_dayshours($seconds) {
$days = intval($seconds / 86400);
$hours = intval(($seconds % 86400) / 3600);
return sprintf('%d days %d hours', $days, $hours);
}
while ($device = db_fetch_object($result)) {
$row = array();
$row[] = $device->serial;
$row[] = $device->resets;
$row[] = unix_to_userlocaltime($device->access);
$row[] = seconds_to_dayshours($device->uptime);
$rows[] = $row;
}
return theme('logger_account_devices_list', $rows);
}
/**
* Theme function for displaying the user's devices
*
* @param $items
* An array of table rows.
*/
function theme_logger_account_devices_list($items) {
if (count($items) > 0) {
$headers = array(t('Serial'), t('Resets'), t('Last heartbeat'), t('Uptime'));
$output = theme('table', $headers, $items);
}
else {
$output = t('No devices available.');
}
return $output;
}
/** /**
* Callback function for the user/x/sensors page * Callback function for the user/x/sensors page
*
* @param $type
* String defining the sensor type
*/ */
function _logger_account_sensors($type = 'electricity') { function _logger_account_sensors($type = 'electricity') {
global $user; global $user;
@ -49,8 +108,6 @@ function _logger_account_sensors($type = 'electricity') {
* *
* @param $items * @param $items
* An array of table rows. * An array of table rows.
*
* @ingroup themeable
*/ */
function theme_logger_account_sensors_list($items) { function theme_logger_account_sensors_list($items) {
if (count($items) > 0) { if (count($items) > 0) {

View File

@ -174,6 +174,16 @@ function logger_menu() {
'access arguments' => array('logger', 1), 'access arguments' => array('logger', 1),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'file' => 'logger.admin.inc', 'file' => 'logger.admin.inc',
'weight' => 2,
);
$items['user/%user_uid_optional/devices'] = array(
'title' => 'Devices',
'page callback' => '_logger_account_devices',
'access callback' => '_logger_account_access',
'access arguments' => array('logger', 1),
'type' => MENU_LOCAL_TASK,
'file' => 'logger.admin.inc',
'weight' => 3,
); );
$items['user/%user_uid_optional/sensors'] = array( $items['user/%user_uid_optional/sensors'] = array(
'title' => 'Sensors', 'title' => 'Sensors',
@ -182,12 +192,12 @@ function logger_menu() {
'access arguments' => array('logger', 1), 'access arguments' => array('logger', 1),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'file' => 'logger.admin.inc', 'file' => 'logger.admin.inc',
'weight' => 3,
); );
return $items; return $items;
} }
function _logger_installation(){ function _logger_installation(){
$output = '<div class="install">'; $output = '<div class="install">';
$output .= "<a class='img' href = 'http://www.flukso.net/installation'><img src='http://www.flukso.net/sites/default/files/images/step1.png' height='120' width='150' alt='step 1'/></a>"; $output .= "<a class='img' href = 'http://www.flukso.net/installation'><img src='http://www.flukso.net/sites/default/files/images/step1.png' height='120' width='150' alt='step 1'/></a>";
@ -477,6 +487,10 @@ function logger_theme() {
'logger_item_list' => array( 'logger_item_list' => array(
'arguments' => array('items' => NULL, 'title' => NULL), 'arguments' => array('items' => NULL, 'title' => NULL),
), ),
'logger_account_devices_list' => array(
'arguments' => array('items' => NULL),
'file' => 'logger.admin.inc',
),
'logger_account_sensors_list' => array( 'logger_account_sensors_list' => array(
'arguments' => array('items' => NULL), 'arguments' => array('items' => NULL),
'file' => 'logger.admin.inc', 'file' => 'logger.admin.inc',