From a2e6948a7ecf288398efd6d46e42ee85b9f31786 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Fri, 5 Mar 2010 15:40:22 +0000 Subject: [PATCH] web: list sensors associated with a user in the account section --- web/drupal/modules/logger/logger.admin.inc | 122 +++++++++++++++++++++ web/drupal/modules/logger/logger.drush.inc | 20 ++++ web/drupal/modules/logger/logger.module | 79 +++---------- 3 files changed, 160 insertions(+), 61 deletions(-) create mode 100644 web/drupal/modules/logger/logger.admin.inc diff --git a/web/drupal/modules/logger/logger.admin.inc b/web/drupal/modules/logger/logger.admin.inc new file mode 100644 index 0000000..f702930 --- /dev/null +++ b/web/drupal/modules/logger/logger.admin.inc @@ -0,0 +1,122 @@ +uid, $type); + + while ($sensor = db_fetch_object($result)) { + $row = array(); + $row[] = $sensor->meter; + $row[] = $type; + $row[] = $sensor->function; + + $rows[] = $row; + } + + return theme('logger_account_sensors_list', $rows); +} + +/** + * Theme function for displaying the user's sensors + * + * @param $items + * An array of table rows. + * + * @ingroup themeable + */ +function theme_logger_account_sensors_list($items) { + if (count($items) > 0) { + $headers = array(t('Sensor'), t('Type'), t('Function')); + $output = theme('table', $headers, $items); + } + else { + $output = t('No sensors available.'); + } + + return $output; +} + +/** + * Callback function for the user/x/privacy page + */ +function _logger_account_privacy() { + $output .= drupal_get_form('_logger_account_privacy_form'); + return $output; +} + +/** + * Generates the privacy form. + */ +function _logger_account_privacy_form() { + global $user; + + $form['privacy'] = array( + '#title' => t('Set your preferred privacy mode'), + '#type' => 'radios', + '#options' => array( + t('Shared within Flukso'), + t('Private'), + ), + '#description' => t("When selecting Private mode, your data stream will not be drawn on other people's graph and all statistics will be marked as 'prv'. Conversely, nobody else's data stream will be drawn on your chart."), + '#default_value' => db_result(db_query("SELECT private + FROM {logger_users} + WHERE uid = %d", $user->uid)), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + return $form; +} + +/** + * Process settings form submissions. + */ +function _logger_account_privacy_form_submit($form, &$form_state) { + global $user; + + // the built-in validation function already checks elements with options + $private = $form_state['values']['privacy']; + db_query("UPDATE {logger_users} + SET private = %d + WHERE uid = %d", $private, $user->uid); + + // page redirection to the dashboard after form submission + $form_state['redirect'] = 'logger'; +} + +/** + * Define the administration settings form for the logger module + */ +function _logger_admin_settings() { +//TODO +} + diff --git a/web/drupal/modules/logger/logger.drush.inc b/web/drupal/modules/logger/logger.drush.inc index 2934552..a4ce398 100644 --- a/web/drupal/modules/logger/logger.drush.inc +++ b/web/drupal/modules/logger/logger.drush.inc @@ -1,5 +1,25 @@ 'Privacy', - 'page callback' => '_logger_privacy', - 'access callback' => '_logger_privacy_access', + 'page callback' => '_logger_account_privacy', + 'access callback' => '_logger_account_access', 'access arguments' => array('logger', 1), 'type' => MENU_LOCAL_TASK, + 'file' => 'logger.admin.inc', + ); + $items['user/%user_uid_optional/sensors'] = array( + 'title' => 'Sensors', + 'page callback' => '_logger_account_sensors', + 'access callback' => '_logger_account_access', + 'access arguments' => array('logger', 1), + 'type' => MENU_LOCAL_TASK, + 'file' => 'logger.admin.inc', ); return $items; @@ -177,7 +186,7 @@ function _logger_installation(){ $output .= "step 3"; $output .= "

STEP 3: ATTACHING THE CURRENT CLAMP
For safety reasons, switch off the main electricity supply. For a single phase supply, attach the current clamp to one of the two cables running from the electricity meter to the fuse box. Close the clamp firmly.

"; $output .= "step 4"; - $output .= "

STEP 4: CONNECTING THE CLAMP'S SENSOR CABLE
Connect the cable from the current clamp to the Fluksometer's input port. Take care of connecting the black and red cable as shown in the drawing on the right. Only apply gentle force when fastening the two screws.

"; + $output .= "

STEP 4: CONNECTING THE CLAMP'S SENSOR CABLE
Connect the cable from the current clamp to the Fluksometer's input port. Take care of connecting the black and red cable as shown in the drawing on the left. Only apply gentle force when fastening the two screws.

"; $output .= "step 4"; $output .= "

STEP 5: POWERING UP
Switch the main electricity supply back on. Activate the Fluksometer by connecting the power plug.

"; $output .= ""; @@ -455,6 +464,10 @@ function logger_theme() { 'logger_item_list' => array( 'arguments' => array('items' => NULL, 'title' => NULL), ), + 'logger_account_sensors_list' => array( + 'arguments' => array('items' => NULL), + 'file' => 'logger.admin.inc', + ), ); } @@ -583,56 +596,7 @@ function theme_logger_item_list($items, $title = NULL) { } /** - * Callback function for the user/x/privacy page - */ -function _logger_privacy() { - $output .= drupal_get_form('_logger_privacy_form'); - return $output; -} - -/** - * Generates the privacy form. - */ -function _logger_privacy_form() { - global $user; - - $form['privacy'] = array( - '#title' => t('Set your preferred privacy mode'), - '#type' => 'radios', - '#options' => array( - t('Shared within Flukso'), - t('Private'), - ), - '#description' => t("When selecting Private mode, your data stream will not be drawn on other people's graph and all statistics will be marked as 'prv'. Conversely, nobody else's data stream will be drawn on your chart."), - '#default_value' => db_result(db_query("SELECT private - FROM {logger_users} - WHERE uid = %d", $user->uid)), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - return $form; -} - -/** - * Process settings form submissions. - */ -function _logger_privacy_form_submit($form, &$form_state) { - global $user; - - // the built-in validation function already checks elements with options - $private = $form_state['values']['privacy']; - db_query("UPDATE {logger_users} - SET private = %d - WHERE uid = %d", $private, $user->uid); - - // page redirection to the dashboard after form submission - $form_state['redirect'] = 'logger'; -} - -/** - * Access callback ensuring the user profile tabs are visible only to their + * Access callback ensuring the user account tabs are visible only to the * owner. * * @param $permission @@ -640,17 +604,10 @@ function _logger_privacy_form_submit($form, &$form_state) { * @param $account * A user object. */ -function _logger_privacy_access($permission, $account) { +function _logger_account_access($permission, $account) { return ($account->uid == $GLOBALS['user']->uid && user_access($permission)); } -/** - * Define the administration settings form for the logger module - */ -function _logger_admin_settings() { -//TODO -} - /** * Implementation of hook_cron(). * Cron will call this hook periodically [e.g. 1 hour interval] to perform housekeeping on the png's.