Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_time_tracker/README.txt,v
retrieving revision 1.3
diff -u -p -r1.3 README.txt
--- README.txt	4 Mar 2007 17:53:14 -0000	1.3
+++ README.txt	24 Apr 2009 15:34:35 -0000
@@ -6,7 +6,5 @@ Once installed you need to allow the tim
 
 Set the visibility of the time tracker block on admin > build > block
 
-This module depends on views to show a list of time tracker entries. It also depends on node relativity module
-
 ________NOTE_________________________________________________________________
 Note that this is a module in a very early stage. It is actually working by showing the total tracked time per node but it lacks, yet, a fully functional tracking entries administration. I would like, also, to have some nice ajax features added. Please, use the feature request form at drupal.org to let me know your thoughts on the features you would like to see in this module.
\ No newline at end of file
Index: node_time_tracker.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_time_tracker/node_time_tracker.info,v
retrieving revision 1.7
diff -u -p -r1.7 node_time_tracker.info
--- node_time_tracker.info	16 Dec 2007 08:59:19 -0000	1.7
+++ node_time_tracker.info	24 Apr 2009 15:34:35 -0000
@@ -1,4 +1,4 @@
 ; $Id: node_time_tracker.info,v 1.7 2007/12/16 08:59:19 sanduhrs Exp $
 name = Node time tracker
 description = Provides a time tracking feature for any node type.
-dependencies = views
\ No newline at end of file
+core = 6.x
\ No newline at end of file
Index: node_time_tracker.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_time_tracker/node_time_tracker.install,v
retrieving revision 1.2
diff -u -p -r1.2 node_time_tracker.install
--- node_time_tracker.install	14 Feb 2007 11:57:37 -0000	1.2
+++ node_time_tracker.install	24 Apr 2009 15:34:35 -0000
@@ -2,31 +2,34 @@
 /* $Id: node_time_tracker.install,v 1.2 2007/02/14 11:57:37 robertgarrigos Exp $ */
 
 /**
+ * Implementation of hook_schema().
+ */
+function node_time_tracker_schema() {
+  $schema['node_time_tracker'] = array(
+    'fields' => array(
+      'ttid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+      'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
+      'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
+      'start' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
+      'stop' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
+      'spend' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
+    ),
+    'primary key' => array('ttid'),
+  );
+
+  return $schema;
+}
+
+/**
  * Implementation of hook_install()
  */
 function node_time_tracker_install() {
-  
-  switch ($GLOBALS['db_type']) {
-    case 'mysqli':
-    case 'mysql':
-      $sql = "CREATE TABLE {node_time_tracker} (
-              ttid INT(10) unsigned  NOT NULL AUTO_INCREMENT ,
-              nid INT(10) unsigned  NOT NULL,
-              uid INT unsigned  NOT NULL,
-              start INT(11) unsigned ,
-              stop INT(11) unsigned  DEFAULT 0,
-              spend INT(11) unsigned ,
-              PRIMARY KEY (ttid)
-              ) /*!40100 DEFAULT CHARACTER SET utf8 */;";
-      db_query($sql);
-      db_query("ALTER TABLE {node_time_tracker} ADD FOREIGN KEY (nid) REFERENCES node(nid)");
-      break;
-  }
+  drupal_install_schema('node_time_tracker');
 }
 
 /**
  * Implementation of hook_uninstall()
  */
 function node_time_tracker_uninstall() {
-  db_query('DROP TABLE {node_time_tracker}');
+  drupal_uninstall_schema('node_time_tracker');
 }
\ No newline at end of file
Index: node_time_tracker.js
===================================================================
RCS file: node_time_tracker.js
diff -N node_time_tracker.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ node_time_tracker.js	24 Apr 2009 15:34:35 -0000
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/**
+ * Ajaxify the start/stop form
+ */
+ 
+var node_time_tracker_timeoutid = 0;
+
+Drupal.node_time_trackerButtonAutoAttach = function() {
+  $('#block-node_time_tracker-0 input[@type=submit]').click(function() {
+    var button = $(this);
+
+    var html = $.ajax({
+      url: '/node/'+ nid +'/ntt/toggle',
+      dataType: "json",
+      success: function(result){
+        if (result['status']) {
+          button.val('Stop');
+          node_time_tracker_timeoutid = setTimeout("node_time_trackerRefresh()", 15000); 
+        }
+        else {
+          button.val('Start');
+          clearTimeout(node_time_tracker_timeoutid);
+        }
+        $('#block-node_time_tracker-0 .time_tracker_status').remove();
+        $('#block-node_time_tracker-0 form').after(result['message']);
+        
+      }
+    });
+
+    return false;
+  });
+}
+
+function node_time_trackerAttachRefresh () {
+    var button = $('#block-node_time_tracker-0 input[@type=submit]');
+    if (button.val() == "Stop") {
+      node_time_trackerRefresh();
+    }
+}
+
+function node_time_trackerRefresh () {
+
+    var html = $.ajax({
+      url: '/node/'+ nid +'/ntt/refresh',
+      dataType: "json",
+      success: function(result){
+        $('#block-node_time_tracker-0 .time_tracker_spend_subtotal').remove();
+        $('#block-node_time_tracker-0 .time_tracker_status').after(result['message']);
+      }
+    });
+    node_time_tracker_timeoutid = setTimeout("node_time_trackerRefresh()", 15000); 
+
+    return false;
+}
+
+// Global Killswitch
+if (Drupal.jsEnabled) {
+  $(document).ready(Drupal.node_time_trackerButtonAutoAttach);
+  $(document).ready(node_time_trackerAttachRefresh);
+}
Index: node_time_tracker.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_time_tracker/node_time_tracker.module,v
retrieving revision 1.14
diff -u -p -r1.14 node_time_tracker.module
--- node_time_tracker.module	15 May 2008 21:57:37 -0000	1.14
+++ node_time_tracker.module	24 Apr 2009 15:34:35 -0000
@@ -2,11 +2,7 @@
 /* $Id: node_time_tracker.module,v 1.14 2008/05/15 21:57:37 robertgarrigos Exp $ */
 
 /**
- * @file node_time_tracker module for drupal 5.x
- *
- * 
- * Developed by Robert Garrigos <robert@garrigos.cat>
- * http://robert.garrigos.cat
+ * @file node_time_tracker module for drupal 6.x
  */
  
  /**
@@ -22,24 +18,12 @@ function node_time_tracker_block($op = '
     );
     return $blocks;
   }
-  else if ($op == 'configure' && $delta == 0) {
-   /* $form['items'] = array(
-      '#type' => 'select',
-      '#title' => t('Number of items'),
-      '#default_value' => variable_get('mymodule_block_items', 0),
-      '#options' => array('1', '2', '3'),
-    );*/
-    return $form;
-  }
-  else if ($op == 'save' && $delta == 0) {
-   /* variable_set('mymodule_block_items', $edit['items']);*/
-  }
   else if ($op == 'view') {
     switch ($delta) {
       case 0:
         $block = array(
           'subject' => t('Time tracking'),
-          'content' => node_time_tracker_display_block($form),
+          'content' => node_time_tracker_display_block(),
         );
         break;
       
@@ -51,27 +35,26 @@ function node_time_tracker_block($op = '
 /**
  * Block content
  */
-function node_time_tracker_display_block($form) {
+function node_time_tracker_display_block() {
   global $user;
   
   if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('admin time tracker')) {
-    $node = node_load(arg(1));
-    if (variable_get("ntt_type_$node->type", 0)) {
+    $node = menu_get_object();
+    $output = '';
+    if (isset($node->type) && variable_get("ntt_type_$node->type", 0)) {
        drupal_add_js('var nid = '. $node->nid, 'inline');
        drupal_add_js(drupal_get_path('module', 'node_time_tracker') .'/node_time_tracker.js');
        
        if ($unfinished = node_time_tracker_get_unfinished($node->nid, $user->uid)) {
-         $output .= drupal_get_form('node_time_tracker_stop_form', $form);
-         $output .= theme_node_time_tracker_toggled($unfinished->start);   
+         $output .= drupal_get_form('node_time_tracker_stop_form');
+         $output .= theme('node_time_tracker_toggled', $unfinished->start);   
        }
        else {
-         $output = drupal_get_form('node_time_tracker_start_form', $form);
+         $output = drupal_get_form('node_time_tracker_start_form');
        }
        
-        $time = node_time_tracker_format_timestamp(node_time_tracker_get_spend($node, $user));
+       $time = node_time_tracker_format_timestamp(node_time_tracker_get_spend($node, $user));
        $output .= theme('node_time_tracker_spend_subtotal', $time, TRUE);
-       // not sure I like this
-       //$output .= l(t('Show all time registers for this node'), 'ttl/'. arg(1));
     }
     return $output;
   }
@@ -80,7 +63,7 @@ function node_time_tracker_display_block
 /**
  * Implementation of hook_form_alter().
  */
-function node_time_tracker_form_alter($form_id, &$form) {
+function node_time_tracker_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'node_type_form') {
     $node_type = $form['old_type']['#value'];
     $form['node_time_tracker'] = array(
@@ -150,7 +133,7 @@ function node_time_tracker_get_unfinishe
 }
 
 /**
- * returns the total time spend on a node
+ * Returns the total time spent on a node.
  *
  * @param $node
  *   object. node
@@ -170,6 +153,7 @@ function node_time_tracker_get_spend($no
     $result = db_query("SELECT spend FROM {node_time_tracker} WHERE nid = %d", $node->nid);
   }
   
+  $total = 0;
   while ($row = db_fetch_object($result)) {
     $total += $row->spend;
   }
@@ -181,14 +165,13 @@ function node_time_tracker_get_spend($no
  */
 function node_time_tracker_link($type, $node = NULL, $teaser = FALSE) {
   $links = array();
- 
-  if (variable_get('ntt_type_'. $node->type, 0)) {
+  if (isset($node->type) && variable_get('ntt_type_'. $node->type, 0)) {
       $links['ntt_total_spend_time'] = array(
         'title' => theme('node_time_tracker_spend_total', node_time_tracker_format_timestamp(node_time_tracker_get_spend($node)), TRUE) ,
         'html' => TRUE,
      );
   }
-  else {
+  else if (module_exists('relativity')) {
     $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $node->nid);
     while ($child = db_fetch_object($result)) {
       $child_node = node_load($child->nid);
@@ -206,73 +189,89 @@ function node_time_tracker_link($type, $
   return $links;
 }
 
-
 /**
  * callback function to list all the time tracking entries
  */
-function node_time_tracker_list($nid = NULL) {
+function node_time_tracker_list($node) {
   $result = pager_query("SELECT n.title, ntt.* FROM {node_time_tracker} ntt
                                           INNER JOIN {node} n ON n.nid = ntt.nid  
                                           WHERE n.nid = %d
-                                          ORDER BY start DESC", 10, 0, NULL, $nid);
+                                          ORDER BY start DESC", 10, 0, NULL, $node->nid);
   
-  $header = array(t('Title'), t('Username'), t('Start'), t('Stop'), t('Spent'));
+  $header = array(t('Title'), t('Username'), t('Start'), t('Stop'), t('Spent'), t('Edit'));
+  $rows = array();
+  $users = array();
   while ($row = db_fetch_object($result)) {
-    $account = user_load(array('uid' => $row->uid));
+    if (!isset($users[$row->uid])) {
+      $users[$row->uid] = user_load(array('uid' => $row->uid));
+      $users[$row->uid]->spent = 0;
+    }
     $rows[] = array(
       l($row->title, 'node/'. $row->nid),
-      theme('username', $account),
+      theme('username', $users[$row->uid]),
       format_date($row->start, 'small'),
       format_date($row->stop, 'small'),
       theme('node_time_tracker_spend_total', node_time_tracker_format_timestamp($row->spend)),
+      l(t('Edit'), 'node/' . $row->nid . '/ntt/' . $row->ttid . '/edit'),
     );
+    $users[$row->uid]->spent += $row->spend;
   }
-  $output = theme('table', $header, $rows);
-  $output .= theme('pager');
 
+  $output = '';
+  if ($rows) {
+    $output .= '<p>User list</p><ul>';
+    foreach ($users as $account) {
+      $output .= '<li>' . theme('username', $account) . ': ' . $account->spent . ' seconds</li>';
+    }
+    $output .= '</ul>';
+    $output .= theme('table', $header, $rows, array("class" => 'ntt_table'));
+    $output .= theme('pager');
+  }
   return $output;
 }
 
 /**
  * Implementation of hook_menu().
  */
-function node_time_tracker_menu($may_cache) {
+function node_time_tracker_menu() {
   $items = array();
-  if ( $may_cache ) {
-    
-    $items[] = array(
-      'path' => 'admin/content/ntt',
-      'title' => t('Time tracker entries'),
-      'access' => user_access('admin time tracker'),
-      'callback' => 'node_time_tracker_admin_content',
-    );    
-               
-  }
-  else {
-    if ((arg(0) == 'node') && is_numeric(arg(1))) {
-      $node = node_load(arg(1));
-      if (variable_get('ntt_type_'. $node->type, 0)) {
-        $items[] = array(
-          'path' => 'node/'. arg(1) .'/ntt',
-          'title' => t('Time tracker'),
-          'callback' => 'node_time_tracker_list',
-          'callback arguments' => arg(1),
-          'access' => user_access('view time tracker'),
-          'type' => MENU_LOCAL_TASK,
-        );
-        $items[] = array(
-          'path' => 'node/'. arg(1) .'/ntt/toggle',
-          'access' => user_access('edit own track entries'),
-          'callback' => 'node_time_tracker_toggle',
-          'callback arguments' => array(arg(1)),
-          'type' => MENU_CALLBACK,
-        );
-      }
-    }    
-  }
-  return $items;
+  $items['node/%/ntt/%/edit'] = array(
+      'title' => 'Edit time entry',
+      'page callback' => 'node_time_tracker_edit_page',
+      'page arguments' => array(1, 3),
+      'access arguments' => array('edit own track entries'),
+      'type' => MENU_CALLBACK,
+  );
+  $items['node/%node/ntt'] = array(
+      'title' => 'Time tracker',
+      'page callback' => 'node_time_tracker_list',
+      'page arguments' => array(1),
+      'access callback' => 'node_time_tracker_access',
+      'access arguments' => array('view time tracker', 1),
+      'type' => MENU_LOCAL_TASK,
+    );
+    $items['node/%/ntt/toggle'] = array(
+      'title' => 'Toggle',
+      'access arguments' => array('edit own track entries'),
+      'page callback' => 'node_time_tracker_toggle',
+      'page arguments' => array(1),
+      'type' => MENU_CALLBACK,
+    );
+    $items['node/%/ntt/refresh'] = array(
+      'title' => 'Refresh',
+      'access arguments' => array('edit own track entries'),
+      'page callback' => 'node_time_tracker_refresh',
+      'page arguments' => array(1),
+      'type' => MENU_CALLBACK,
+    );
+
+    return $items;
 }
  
+function node_time_tracker_access($perm, $node) {
+  return user_access($perm) && isset($node->ntt_spend);
+}
+
 /**
  * Implementation of hook_nodeapi().
  */
@@ -286,6 +285,7 @@ function node_time_tracker_nodeapi(&$nod
       }
       break;
     case 'submit':
+    case 'presave':
       break;
     case 'insert':
       break;
@@ -297,13 +297,15 @@ function node_time_tracker_nodeapi(&$nod
       */
       break;
     case 'view':
-      if ($node->ntt_spend) {
+      if (isset($node->ntt_spend)) {
         $node->content['ntt_total_spend_time'] = array(
           '#value' => theme('node_time_tracker_spend', node_time_tracker_format_timestamp($node->ntt_spend), TRUE) ,
           '#weight' => 10,
         );
       }
       //check if the node is a parent
+      $result = FALSE;
+      $time = 0;
       if (module_exists('casetracker') && $node->type == 'casetracker_basic_project') {
         $result = db_query('SELECT nid FROM {casetracker_case} WHERE pid = %d', $node->nid);
       }
@@ -335,17 +337,7 @@ function node_time_tracker_perm() {
  * Time tracking start form
  */
 function node_time_tracker_start_form() {
-  global $user;
-  $nid = arg(1);
     
-  $form['nid'] = array(
-   '#type' => 'hidden',
-   '#value' => $nid,
-  );
-  $form['uid'] = array(
-   '#type' => 'hidden',
-   '#value' => $user->uid,
-  );
   $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Start'),
@@ -354,9 +346,10 @@ function node_time_tracker_start_form() 
 }
 
 
-function node_time_tracker_start_form_submit($form_id, $form_values) {
+function node_time_tracker_start_form_submit($form, &$form_state) {
   global $user;
-  ntt_start_time($form_values['nid'], $user->uid);
+  $node = menu_get_object();
+  ntt_start_time($node->nid, $user->uid);
 }
 
 /**
@@ -370,7 +363,7 @@ function node_time_tracker_start_form_su
 function ntt_start_time($nid, $uid) {
   $unfinished = node_time_tracker_get_unfinished($nid, $uid);
   if ($unfinished == FALSE) { 
-    db_query("INSERT INTO {node_time_tracker} SET nid = %d, uid = %d, start = %d", $nid, $uid, time());
+    db_query("INSERT INTO {node_time_tracker} SET stop = 0, spend = 0, nid = %d, uid = %d, start = %d", $nid, $uid, time());
   }
 }
 
@@ -378,17 +371,7 @@ function ntt_start_time($nid, $uid) {
  * Time tracking stop form
  */
 function node_time_tracker_stop_form() {
-  global $user;
-  $nid = arg(1);
-  
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $nid,
-  );
-  $form['uid'] = array(
-    '#type' => 'hidden',
-    '#value' => $user->uid,
-  );
+ 
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Stop'),
@@ -397,9 +380,10 @@ function node_time_tracker_stop_form() {
 }
 
 
-function node_time_tracker_stop_form_submit($form_id, $form_values) {
+function node_time_tracker_stop_form_submit($form, &$form_state) {
   global $user;
-  ntt_stop_time($form_values['nid'], $user->uid);
+  $node = menu_get_object();
+  ntt_stop_time($node->nid, $user->uid);
 }
 
 /**
@@ -426,110 +410,24 @@ function node_time_tracker_spend_field_v
   return theme('node_time_tracker_spend_total', node_time_tracker_format_timestamp($value));
 }
 
-/**
- * Views integration
- */
-function node_time_tracker_views_tables() {
-  $tables['node_time_tracker'] = array(
-    'name' => 'node_time_tracker',
-    'provider' => 'internal',   
-    'join' => array(
-      'type' => 'inner',
-      'left' => array(
-        'table' => 'node',
-        'field' => 'nid'
-      ),
-      'right' => array(
-        'field' => 'nid'
-      ),
-    ),
-    'fields' => array(
-      'start' => array(
-        'name' => t('Time tracker: start'),
-        'help' => t('Start time.'),
-        'handler' => views_handler_field_dates(),
-        'sortable' => true,
-      ),
-      'stop' => array(
-        'name' => t('Time tracker: stop'),
-        'help' => t('Stop time.'),
-        'handler' => views_handler_field_dates(),
-        'sortable' => true,
-      ),
-      'spend' => array(
-        'name' => t('Time tracker: time spend'),
-        'help' => t('Time spend.'),
-        'handler' => 'node_time_tracker_spend_field_views_handler',
-        'sortable' => true,
-      ),
-    ),
-  );
-
-  return $tables;
-}
-
-function node_time_tracker_views_default_views() {
-  $view = new stdClass();
-  $view->name = 'Time_tracker';
-  $view->description = 'time tracker list';
-  $view->access = array();
-  $view->view_args_php = '';
-  $view->page = TRUE;
-  $view->page_title = '';
-  $view->page_header = '';
-  $view->page_header_format = '1';
-  $view->page_footer = '';
-  $view->page_footer_format = '1';
-  $view->page_empty = '';
-  $view->page_empty_format = '1';
-  $view->page_type = 'table';
-  $view->url = 'ttl';
-  $view->use_pager = TRUE;
-  $view->nodes_per_page = '15';
-  $view->sort = array();
-  $view->argument = array(
-    array(
-      'type' => 'nid',
-      'argdefault' => '2',
-      'title' => '',
-      'options' => '0',
-      'wildcard' => '',
-      'wildcard_substitution' => '',
+function node_time_tracker_theme() {
+  return array(
+    'node_time_tracker_spend_total' => array(
+      'arguments' => array('time', 'string' => FALSE),
     ),
-  );
-  $view->field = array(
-    array(
-      'tablename' => 'node',
-      'field' => 'title',
-      'label' => t('Title'),
-      'handler' => 'views_handler_field_nodelink',
-      'options' => 'link',
+    'node_time_tracker_started' => array(
+      'arguments' => array('timestap'),
     ),
-    array(
-      'tablename' => 'node_time_tracker',
-      'field' => 'start',
-      'label' => t('Start'),
-      'handler' => 'views_handler_field_date_small',
-      'sortable' => '1',
-      'defaultsort' => 'DESC',
+    'node_time_tracker_spend_subtotal' => array(
+      'arguments' => array('time', 'string' => FALSE),
     ),
-    array(
-      'tablename' => 'node_time_tracker',
-      'field' => 'stop',
-      'label' => t('Stop'),
-      'handler' => 'views_handler_field_date_small',
+    'node_time_tracker_toggled' => array(
+      'arguments' => array('timestamp', 'status' => TRUE),
     ),
-    array(
-      'tablename' => 'node_time_tracker',
-      'field' => 'spend',
-      'label' => t('Time spend'),
+    'node_time_tracker_refreshed' => array(
+      'arguments' => array('timestamp', 'status' => TRUE),
     ),
   );
-  $view->exposed_filter = array();
-  $view->requires = array(node, node_time_tracker);
-  $views[$view->name] = $view;
-
-  return $views;
 }
 
 /**
@@ -538,7 +436,7 @@ function node_time_tracker_views_default
  * @param $time
  *   time object created with node_time_tracker_format_timestamp()
  * @param $string
- *   boolean. if true string will be appended, otherwise only time will be shown (default)
+ *   boolean. if TRUE string will be appended, otherwise only time will be shown (default)
  * @return
  *   html string
  */
@@ -546,8 +444,8 @@ function theme_node_time_tracker_spend_t
   $hours = $time->hours < 10 ? '0'. $time->hours : $time->hours;
   $minutes = $time->minutes < 10 ? '0'. $time->minutes : $time->minutes;
   $seconds = $time->seconds < 10 ? '0'. $time->seconds : $time->seconds;
-  $output .= '<div class="time_tracker_spend time_tracker_spend_total">';
-  $output .= $string ? t('Total time spend:') .' ' : '';
+  $output = '<div class="time_tracker_spend time_tracker_spend_total">';
+  $output .= $string ? t('Total time spent:') . ' ' : '';
   $output .= '<span class="time_tracker_spend_time">'. $hours .':'. $minutes .':'. $seconds .'</span>';
   $output .= '</div>';
   return $output;
@@ -572,7 +470,7 @@ function theme_node_time_tracker_started
  * @param $time
  *   time object created with node_time_tracker_format_timestamp()
  * @param $string
- *   boolean. if true string will be appended, otherwise only time will be shown (default)
+ *   boolean. if TRUE string will be appended, otherwise only time will be shown (default)
  * @return
  *   html string
  */
@@ -581,8 +479,8 @@ function theme_node_time_tracker_spend_s
   $minutes = $time->minutes < 10 ? '0'. $time->minutes : $time->minutes;
   $seconds = $time->seconds < 10 ? '0'. $time->seconds : $time->seconds;
   
-  $output .= '<div class="time_tracker_spend time_tracker_spend_subtotal">';
-  $output .= $string ? t('Your time spend:') .' ' : '';
+  $output = '<div class="time_tracker_spend time_tracker_spend_subtotal">';
+  $output .= $string ? t('Your time spent:') .' ' : '';
   $output .= '<span class="time_tracker_spend_time">'. $hours .':'. $minutes .':'. $seconds .'</span>';
   $output .= '</div>';
   
@@ -600,6 +498,16 @@ function theme_node_time_tracker_toggled
   $output = '<div class="time_tracker_status time_tracker_'. ($status ? 'started' : 'stopped') .'">'. ($status ? t('Started') : t('Stopped')) .' '. format_date($timestap, 'small') .'</div>';
   return $output;
 }
+
+function theme_node_time_tracker_refreshed($time, $status = TRUE) {
+  $hours = $time->hours < 10 ? '0'. $time->hours : $time->hours;
+  $minutes = $time->minutes < 10 ? '0'. $time->minutes : $time->minutes;
+  $seconds = $time->seconds < 10 ? '0'. $time->seconds : $time->seconds;
+  
+  $output = '<div class="time_tracker_spend time_tracker_spend_subtotal">'. t('Your time spent:') .' '. $hours .':'. $minutes .':'. $seconds .'</div>';
+  return $output;
+}
+
 /**
  * Callback function to toggle time tracking via Ajax 
  */
@@ -616,7 +524,7 @@ function node_time_tracker_toggle($nid, 
       $result = db_query("UPDATE {node_time_tracker} SET stop = %d, spend = %d WHERE nid = %d AND start = %d AND uid = %d", time(), $spend, $nid, $unfinished->start, $uid);
     }
     else {
-      $result = db_query("INSERT INTO {node_time_tracker} SET nid = %d, uid = %d, start = %d", $nid, $uid, time());
+      $result = db_query("INSERT INTO {node_time_tracker} SET stop = 0, spend = 0, nid = %d, uid = %d, start = %d", $nid, $uid, time());
     }
   }
   $status = $unfinished ? FALSE : TRUE;
@@ -631,4 +539,99 @@ function node_time_tracker_toggle($nid, 
     'total' => node_time_tracker_format_timestamp(node_time_tracker_get_spend($node)),
   );
   print drupal_to_js($output);
-}
\ No newline at end of file
+}
+
+function node_time_tracker_refresh($nid, $uid = NULL) {
+  if (!$uid) {
+    global $user;
+    $uid = $user->uid;
+  }
+  
+  if (is_numeric($nid) AND is_numeric($uid)) {
+    //TODO: check for node existence and trackability
+    if ($unfinished = node_time_tracker_get_unfinished($nid, $uid)) {
+      $now = time();
+      $spend = $now - $unfinished->start;
+    }
+  }
+  
+  $status = $unfinished ? FALSE : TRUE;
+  $node->nid = $nid;
+  $user->uid = $uid;
+  $output = array(
+    'nid' => $nid,
+    'uid' => $uid,
+    'status' => $status,
+    'message' => theme('node_time_tracker_refreshed', node_time_tracker_format_timestamp($spend), $status),
+    'subtotal' => node_time_tracker_format_timestamp(node_time_tracker_get_spend($node, $user)),
+    'total' => node_time_tracker_format_timestamp(node_time_tracker_get_spend($node)),
+  );
+  print drupal_to_js($output);
+}
+
+function node_time_tracker_edit_page($nid, $nttid) {
+  
+  $output = 'Edit entry ' . $nttid;
+
+  if (is_numeric($nid) && is_numeric($nttid)) {
+    $output .= drupal_get_form ('node_time_tracker_edit_form', $nid, $nttid);
+  }
+  
+  return $output;
+
+}
+
+function node_time_tracker_edit_form(&$form_state, $nid, $nttid) {
+
+  if (module_exists('date')) {
+    module_load_include('inc', 'date_api', 'date_api_elements');
+  }
+  
+  $ntt = db_fetch_object(db_query("SELECT * FROM {node_time_tracker} WHERE ttid = %d AND nid = %d LIMIT 1", $nttid, $nid));
+  $start = date_format(date_make_date($ntt->start, date_default_timezone_name(), DATE_UNIX), 'Y-m-d H:i:s');
+  $stop  = date_format(date_make_date($ntt->stop,  date_default_timezone_name(), DATE_UNIX), 'Y-m-d H:i:s');
+
+  $form = array();
+  $form['start'] = array(
+   '#type' => 'date_select',
+   '#title' => t('Start time'),
+   '#default_value' => $start,
+  );
+
+  $form['stop'] = array(
+   '#type' => 'date_select',
+   '#title' => t('Stop time'),
+   '#default_value' => $stop,
+  );
+
+  $form['submit'] = array(
+   '#type' => 'submit',
+   '#value' => t('Save'),
+  );
+
+  $form['#redirect'] = 'node/' . $ntt->nid . '/ntt';
+
+  return $form;
+  
+}
+
+function node_time_tracker_edit_form_validate($form, $form_state) {
+  $start = $form_state['values']['start'];
+  $stop = $form_state['values']['stop'];
+  
+  if ($start > $stop) {
+    form_set_error ('start', 'Start must be less than stop.');
+    form_set_error ('stop', 'Stop must be greater than start.');
+  }
+}
+
+function node_time_tracker_edit_form_submit($form, $form_state) {
+  $start = date_convert($form_state['values']['start'], DATE_DATETIME, DATE_UNIX, date_default_timezone_name());
+  $stop = date_convert($form_state['values']['stop'], DATE_DATETIME, DATE_UNIX, date_default_timezone_name());
+  $nid = $form['#parameters'][2]; 
+  $nttid = $form['#parameters'][3]; 
+  $spend = $stop - $start;
+
+  db_query("UPDATE {node_time_tracker} SET start = %d, stop = %d, spend = %d WHERE ttid = %d AND nid = %d", $start, $stop, $spend, $nttid, $nid);
+}
+
