diff --git a/web/drupal/modules/logger/logger.admin.inc b/web/drupal/modules/logger/logger.admin.inc index f702930..434c768 100644 --- a/web/drupal/modules/logger/logger.admin.inc +++ b/web/drupal/modules/logger/logger.admin.inc @@ -1,4 +1,5 @@ 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 + * + * @param $type + * String defining the sensor type */ function _logger_account_sensors($type = 'electricity') { global $user; @@ -49,8 +108,6 @@ function _logger_account_sensors($type = 'electricity') { * * @param $items * An array of table rows. - * - * @ingroup themeable */ function theme_logger_account_sensors_list($items) { if (count($items) > 0) { diff --git a/web/drupal/modules/logger/logger.module b/web/drupal/modules/logger/logger.module index fee86aa..55bfc47 100644 --- a/web/drupal/modules/logger/logger.module +++ b/web/drupal/modules/logger/logger.module @@ -174,6 +174,16 @@ function logger_menu() { 'access arguments' => array('logger', 1), 'type' => MENU_LOCAL_TASK, '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( 'title' => 'Sensors', @@ -182,12 +192,12 @@ function logger_menu() { 'access arguments' => array('logger', 1), 'type' => MENU_LOCAL_TASK, 'file' => 'logger.admin.inc', + 'weight' => 3, ); return $items; } - function _logger_installation(){ $output = '