diff --git a/css/time_tracker.css b/css/time_tracker.css
index d0ee302..c8ed336 100644
--- a/css/time_tracker.css
+++ b/css/time_tracker.css
@@ -27,28 +27,30 @@
   padding: 0px;
 }
 
-#edit-username-wrapper,
+
+.form-item-username,
 #edit-time-wrapper,
-#edit-duration-wrapper,
-#edit-activity-wrapper,
+
+.form-item-duration,
+.form-item-activity,
 #edit-deductions-wrapper {
   float:left;
 }
 
-#edit-duration-wrapper input {
+.form-item-duration input {
   width: 60px;
 }
 
-#edit-username-wrapper {
+.form-item-username {
   /*margin-right: 20px;*/
 /*  width: 200px;*/
 }
 
-#edit-username-wrapper input {
+.form-item-username input {
   /*width: 200px;*/
 }
 
-#edit-activity-wrapper select {
+.form-item-activity select {
 /*  min-width: 200px;*/
 }
 
@@ -109,7 +111,7 @@
 #edit-deductions-1-wrapper {
   float:left;
 }
-
+#comment-form .form-item,
 #edit-locked-1-wrapper,
 #edit-billable-1-wrapper,
 #edit-billed-1-wrapper {
diff --git a/time_sheet/css/time_sheet.css b/time_sheet/css/time_sheet.css
old mode 100755
new mode 100644
index 0d13bff..a8be36e
--- a/time_sheet/css/time_sheet.css
+++ b/time_sheet/css/time_sheet.css
@@ -1,21 +1,21 @@
-/* $Id$ */
-
-.show-case { display:none; }
-.secret-submit {display:none;}
-
-#case-details-monday,
-#case-details-tuesday,
-#case-details-wednesday,
-#case-details-thursday,
-#case-details-friday { padding-bottom:10px; }
-
-.crayon-swatch { float:left; }
-.time-sheet-case { margin-left:5px; }
-.case-details { margin:10px 0 5px 0; padding:10px; border:1px solid #ccc; background-color:#eee; }
-.time-sheet-header { font-size:20px; color:#ccc; line-height:30px; }
-
-/*.hidden {
-  display:none;
-}*/
-
-
+/* $Id$ */
+
+.show-case { display:none; }
+.secret-submit {display:none;}
+
+#case-details-monday,
+#case-details-tuesday,
+#case-details-wednesday,
+#case-details-thursday,
+#case-details-friday { padding-bottom:10px; }
+
+.crayon-swatch { float:left; }
+.time-sheet-case { margin-left:5px; }
+.case-details { margin:10px 0 5px 0; padding:10px; border:1px solid #ccc; background-color:#eee; }
+.time-sheet-header { font-size:20px; color:#ccc; line-height:30px; }
+
+/*.hidden {
+  display:none;
+}*/
+
+
diff --git a/time_sheet/time_sheet.info b/time_sheet/time_sheet.info
index 78db5fc..17a6640 100644
--- a/time_sheet/time_sheet.info
+++ b/time_sheet/time_sheet.info
@@ -1,5 +1,5 @@
 name = Time Sheet
 description = Provides time sheet functionality for extra accountability.
 package = Time Tracker
-core = 6.x
+core = 7.x
 dependencies[] = time_tracker
\ No newline at end of file
diff --git a/time_sheet/time_sheet.module b/time_sheet/time_sheet.module
index a0760cd..87b1a44 100644
--- a/time_sheet/time_sheet.module
+++ b/time_sheet/time_sheet.module
@@ -1,723 +1,709 @@
-<?php
-// $Id: time_sheet.module,v 1.5 2010/07/14 23:46:17 codi Exp $
-
-/**
- * @file
- * Enables time sheet entry for users.
- */
-
-function time_sheet_init() {
-  drupal_add_css(drupal_get_path('module', 'time_sheet') .'/css/time_sheet.css');
-}
-
-/**
- * Implementation of hook_perm().
- */
-function time_sheet_perm() {
-  if (module_exists('casetracker')) {
-    return array('administer time sheet', 'view time sheet entries', 'enter time on time sheet for casetracker cases');
-  }
-  else {
-    return array('administer time sheet', 'view time sheet entries');
-  }
-}
-
-/**
- * Implementation of hook_help().
- */
-function time_sheet_help($section, $arg) {
-  switch ($section) {
-    case 'admin/help#time_sheet':
-      return t("<h2>Time Sheet</h2>
-        <p>The time sheet provides a simple weekly summary of time entries for a give user. It can be found at (user/%user_id/time_sheet). There will also be a link as a local task (tab) on the user profile page.</p>
-        <p>Settings for the Time Sheet can be found at admin/settings/time_tracker/time_sheets</p>
-        ");
-      break;
-  }
-}
-
-/**
- * Custom Access Control
- */
-function time_sheet_view_access($account) {
-  if (is_numeric($account)) {
-    $account = user_load($account);
-  }
-  // The user is not blocked and logged in at least once.
-  if (!$account->access || !$account->status) {
-    return false;
-  }
-  if ($account && $account->uid) {
-    if ((user_access('view all time tracker entries') && user_access('view time sheet entries')) || user_access('administer users')) {
-      return true;
-    }
-    if ((user_access('view own time tracker entries') && user_access('view time sheet entries')) && $GLOBALS['user']->uid == $account->uid) {
-      return true;
-    }
-  }
-  return false;
-}
-
-/*
- * Implementation of hook_menu().
- *
- * TODO: Add a menu item for administrators to view finalized time sheet entries.
- */
-function time_sheet_menu() {
-  $items = array();
-  $items['user/%user/time_sheet'] = array(
-    'title' => 'Time Sheet',
-    'description' => 'My Time Sheet',
-    'page callback' => 'time_sheet_page',
-    'page arguments' => array(1),
-    'access callback' => 'time_sheet_view_access',
-    'access arguments' => array(1),
-    'type' => MENU_LOCAL_TASK,
-  );
-  $items['time_sheet/add_time/%user'] = array(
-    'page callback' => 'time_sheet_add_time',
-    'access callback' => 'time_sheet_view_access',
-    'access arguments' => array(2),
-    'type' => MENU_CALLBACK,
-  );
-  $items['admin/settings/time_tracker/time_sheets'] = array(
-    'title' => 'Time Sheet',
-    'description' => 'Configuration settings for the time tracker time sheets.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('time_sheet_settings_form'),
-    'access arguments' => array('administer time sheet'),
-    'type' => MENU_LOCAL_TASK,
-    'parent' => 'admin/settings/time_tracker',
-  );
-  return $items;
-}
-
-/**
- * Implementation of hook_form().
- */
-function time_sheet_settings_form() {
-  $form = array();
-  $form['time_sheet_settings']['time_sheet_week_start'] = array(
-    '#type' => 'select',
-    '#title' => t('First day of week'),
-    '#default_value' => variable_get('time_sheet_week_start', 'monday'),
-    '#options' => array(
-      'sunday' => t('Sunday'),
-      'monday' => t('Monday'),
-      'tuesday' => t('Tuesday'),
-      'wednesday' => t('Wednesday'),
-      'thursday' => t('Thursday'),
-      'friday' => t('Friday'),
-      'saturday' => t('Saturday'),
-    ),
-  );
-
-  $form['time_sheet_settings']['time_sheet_days_of_week'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Days of the week'),
-    '#default_value' => variable_get('time_sheet_days_of_week', array('monday', 'tuesday', 'wednesday', 'thursday', 'friday')),
-    '#options' => array(
-      'sunday' => t('Sunday'),
-      'monday' => t('Monday'),
-      'tuesday' => t('Tuesday'),
-      'wednesday' => t('Wednesday'),
-      'thursday' => t('Thursday'),
-      'friday' => t('Friday'),
-      'saturday' => t('Saturday'),
-    ),
-  );
-
-  return system_settings_form($form);
-}
-
-/**
- * Implementation of hook_forms()
- */
-function time_sheet_forms($form_id, $args) {
-  if (strpos($form_id, 'time_sheet_case_list_form') !== FALSE) {
-    $forms[$form_id] = array(
-      'callback' => 'time_sheet_case_list_form',
-    );
-  }
-  return $forms;
-}
-
-/**
- * The users time sheet page callback.
- *
- * @desc This callback displays a users time_sheet defaulting to the
- * current week.
- *
- * @param $user
- *    Can be a $user object, a $uid or left out entirely to load the current user
- */
-function time_sheet_page($user = NULL) {
-  // Display a message if no nodes are set up to track time on
-  $tracking_time = FALSE;
-  foreach (node_get_types() as $key => $value) {
-    if (time_tracker_is_tracking_time($key)) {
-      $tracking_time = TRUE;
-      break;
-    }
-  }
-  if (!$tracking_time) {
-    drupal_set_message("No content types have been set up to track time on. This sheet will not be useful until you've set up at least one content type on which to track time. To begin tracking time, you first must enable time tracking on at least one content type. You can do so on any content type's edit page at admin/content/node-type/%content-type-name");
-  }
-  return theme('time_sheet_user_page', $user);
-}
-
-/************************************************************************
- * THEME FUNCTIONS
-*************************************************************************/
-
-function time_sheet_theme() {
-  return array(
-    'time_sheet_user_page' => array(),
-  );
-}
-
-/**
- * Theme function for the time_sheet user page
- *
- * @desc This callback displays a users time_sheet defaulting to the
- * current week.
- *
- * @param $user
- *    Can be a $user object, a $uid or left out entirely to load the current user
- *
- * @return
- *    A themed table of time entry data
- */
-function theme_time_sheet_user_page($user = NULL) {
-
-  //Validates the user being passed in the path is a number (uid)
-  if (is_numeric($user)) {
-    $user = user_load($user);
-  } // Load current user if it's null
-  elseif ($user == NULL) {
-    global $user;
-  }
-
-  // Get a start timestamp from the url parameters or set a default.
-  if (!isset($_GET['start'])) {
-    $start = time();
-  } else {
-    $start = $_GET['start'];
-  }
-
-  // Create a lookup table of time stamps for the week
-  $date_lookup = array('monday' => strtotime(date("Y\WW1", $start)),
-                'tuesday' => strtotime(date("Y\WW2", $start)),
-                'wednesday' => strtotime(date("Y\WW3", $start)),
-                'thursday' => strtotime(date("Y\WW4", $start)),
-                'friday' => strtotime(date("Y\WW5", $start)),
-                'saturday' => strtotime(date("Y\WW6", $start)),
-                'sunday' => strtotime(date("Y\WW7", $start)));
-
-  // Get the configured days of the week
-  $days_of_week = variable_get('time_sheet_days_of_week', array('monday', 'tuesday', 'wednesday', 'thursday', 'friday'));
-  // Get the configured first day of the week
-  $first_day = variable_get('time_sheet_week_start', 'monday');
-  // A variable to store days at the beginning of the week
-  // to be moved to the end of the week
-  $days_at_end = array();
-
-  // remove items at the beginning of the week until we get to the configured $first_day
-  while (current($days_of_week) != $first_day && current($days_of_week)) {
-    $days_at_end[] = array_shift($days_of_week);
-  }
-
-  // Put the days from the beginning at the end
-  $days_of_week = array_merge($days_of_week, $days_at_end);
-
-  // create a new array of the ordered days of the week with timestamps
-  $days = array();
-  foreach ($days_of_week as $day) {
-    if(!$day) {
-      continue;
-    }
-    $days[$day] = $date_lookup[$day];
-  }
-
-  // Determine the neighbouring weeks timestamps.
-  $next_week = strtotime('+ 1 week', $days[$first_day]);
-  $prev_week = strtotime('- 1 week', $days[$first_day]);
-
-  // Output the week switcher.
-  $output .= '<span class="time-sheet-header">';
-  $output .= l(t('&laquo;'), $_GET['q'], array('query' => array('start' => $prev_week), 'html' => 'TRUE'));
-  $output .= ' ' . date("l, M jS", reset($days)) . ' - ' . date("l, M jS", end($days)) . ' ';
-  $output .= l(t('&raquo;'), $_GET['q'], array('query' => array('start' => $next_week), 'html' => 'TRUE'));
-  $output .= '</span>';
-
-  // Loop through days of the week pulling time entries and generating a table.
-  foreach ($days as $day => $stamp) {
-    // The header displaying the date
-    $header = array(array('data' => date("l, M jS Y", $stamp), 'colspan' => 2));
-    // Rows Variable for later theme_table-ing
-    $rows = array();
-    // Get the all the time tracker entries for the date we're on
-    $sql = "SELECT * FROM {time_tracker_entry}
-            WHERE uid = %d
-            AND timestamp BETWEEN %d AND %d
-            ORDER BY teid";
-    $time_entry_results = db_query($sql, $user->uid, $stamp, (strtotime("+1 day", $stamp)-1));
-    $total_duration = 0;
-    // Loop throug each
-    while ($time_entry_result = db_fetch_object($time_entry_results)) {
-      // Container for row data to display a time entry
-      $row = array();
-      // Load the time entry node object
-      $time_entry = node_load(array('nid' => $time_entry_result->nid));
-      // Little extra love for casetracker
-      if (module_exists('casetracker')) {
-        // Load the casetracker project node object
-        $project = node_load(array('nid' => $time_entry->casetracker->pid));
-        $project_link = ' in ' . l($project->title, 'node/' . $project->nid, array('attributes' => array('class' => 'time-sheet-project')));
-      }
-      // The little colorful project icon next to time entries in the time_sheet
-      // And the time_entry item name. Both linked
-      $row[] = l($time_entry->title, 'node/' . $time_entry->nid, array('attributes' => array('class' => 'time-sheet-node'))) . $project_link;
-      // The amount of time logged for this item
-      $row[] = array('data' => format_hours_to_hours_and_minutes($time_entry_result->duration - $time_entry_result->deductions), 'align' => 'right');
-      // On going add-up of the total duration of time logged this week
-      $total_duration = $total_duration + ($time_entry_result->duration - $time_entry_result->deductions);
-      // Add the row to the rows
-      $rows[] = array('data' => $row);
-    }
-
-    // As long as this day has a time entry, the row array will
-    // be populated with more than 1 item
-    if (count($row) > 1) {
-      $row = array();
-      $row[] = '<strong>' . t("Total hours for") . " " . date("l", $stamp) . '</strong>';
-      $row[] = array('data' => '<strong>' . format_hours_to_hours_and_minutes($total_duration) . '</strong>', 'align' => 'right');
-      $rows[] = array('data' => $row);
-    } else {
-      $row = array();
-      $row[] = array('data' => t("No time entered."), 'colspan' => 2);
-      $rows[] = array('data' => $row);
-    }
-
-    $row = array();
-    // Put the form to add a case for this day at the bottom of the day's table
-    if (module_exists('casetracker') && user_access('enter time on time sheet for casetracker cases')) {
-      $row[] = array('data' => drupal_get_form('time_sheet_case_list_form_' . $day, $user, $day, $stamp), 'colspan' => 2);
-      $rows[] = array('data' => $row, 'id' => 'case-details-' . $day);
-    }
-
-
-    // Add this day to the table
-    $output .= theme('table', $header, $rows, array('id' => 'time-sheet-' . $day));
-  }
-
-  return $output;
-}
-
-
-/************************************************************************
- * CASETRACKER TIME ENTRY FORM ON TIME SHEET
-*************************************************************************/
-
-/**
- * @desc Creates the form that provides the user with a select list of cases.
- * Implements Drupals AHAH for ajax type form submissions.
- *
- * @param $form_state
- * @param $user
- * @param $day
- */
-function time_sheet_case_list_form($form_state, $user, $day, $stamp) {
-  $form = array();
-  $form['time_sheet'][$day]['#cache'] = TRUE;
-  //$form['#submit'][] = 'time_sheet_add_time_submit_handler';
-
-  $form['time_sheet'][$day]['timestamp'] = array(
-    '#type' => 'hidden',
-    '#value' => $stamp,
-  );
-
-  $options = _time_sheet_case_list_options($user);
-
-  $form['time_sheet'][$day]['case_list'] = array(
-    '#type' => 'select',
-    '#title' => t('Select a case'),
-    '#options' => $options,
-    '#ahah' => array(
-      'path' => 'time_sheet/add_time/' . $user->uid,
-      'wrapper' => 'case-form-' . $day,
-      'event' => 'change',
-    ),
-  );
-
-  // CSS hides this button.
-  // Submit handlers defined in the ahah form do not get registered
-  // This hidden button is will be passed as the 'clicked_button'
-  // When the ahah submit button is pressed
-  $form['time_sheet'][$day]['secret_submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Secret Submit'),
-    '#attributes' => array('class' => 'secret-submit'),
-    '#validate' => array('time_sheet_add_time_submit_handler_validate'),
-    '#submit' => array('time_sheet_add_time_submit_handler'),
-  );
-
-  $form['time_sheet'][$day]['case_form_wrapper'] = array(
-    '#type' => 'markup',
-    '#tree' => TRUE,
-    '#value' => '<div id="case-form-' . $day . '"></div>',
-  );
-
-  return $form;
-}
-
-
-/**
- * Page callback For when a user selects a case to add time to from the time sheet
- */
-function time_sheet_add_time() {
-  global $user;
-
-  // The usual AHAH stuff that needs to be here for this to work....
-  $form_state = array('storage' => NULL, 'submitted' => FALSE);
-  $form_build_id = $_POST['form_build_id'];
-  $form = form_get_cache($form_build_id, $form_state);
-  $args = $form['#parameters'];
-  $form_id = array_shift($args);
-  $form_state['post'] = $form['#post'] = $_POST;
-  $form['#programmed'] = $form['#redirect'] = FALSE;
-
-  $form = array();
-
-  $case = node_load(array('nid' => $form_state['post']['case_list']));
-  $project = node_load(array('nid' => $case->casetracker->pid));
-
-  // Grab the total time spent on this ticket
-  $case_results = db_query("SELECT * FROM {time_tracker_entry} WHERE nid = %d AND uid = %d", $case->nid, $user->uid);
-  $total_time = 0;
-  while ($result_case = db_fetch_object($case_results)) {
-    $total_time = $total_time + $result_case->duration;
-  }
-  // Grab the total time estimate for this ticket
-  $total_estimate = db_result(db_query("SELECT estimate FROM {time_estimate_entry} WHERE nid = %d", $case->nid));
-
-  // add some case details so we know what we're dealing with
-  $form['time_sheet']['case_details'] = array(
-    '#type' => 'markup',
-    '#value' => '<h3>' . $project->title . '</h3><p>' . $case->teaser . '</p><p><em>' . t('Time spent by you on this case so far: ') . format_plural($total_time, '1 hour', '@count hours') . '</em></p><p><em>' . t('Estimated time for this ticket: ') . format_plural($total_estimate, '1 hour', '@count hours') . '</em></p>',
-    '#prefix' => '<div class="case-details">',
-    '#suffix' => '</div>',
-    '#weight' => -10,
-  );
-
-  $case_status_options = casetracker_realm_load('status');
-  $default_status = !empty($case->casetracker->case_status_id) ? $case->casetracker->case_status_id : variable_get('casetracker_default_case_status', key($case_status_options));
-
-
-  // We need to know what to track the time on (nodes or comments)
-  // But only if for some reason this person is tracking time on
-  // both nodes and comments
-  if (time_tracker_is_tracking_time($case->type) == 'both') {
-    $track_time_on_options = array(
-      'node' => 'Node',
-      'comment' => 'Comment',
-    );
-    $form['time_sheet']['track_time_on_what'] = array(
-      '#type' => 'select',
-      '#title' => t('Track Time On'),
-      '#default_value' => 'comment',
-      '#options' => $track_time_on_options,
-    );
-  }
-  elseif (time_tracker_is_tracking_time($case->type) == 'node') {
-    $form['time_sheet']['track_time_on_what'] = array(
-      '#type' => 'select',
-      '#title' => t('Track Time On'),
-      '#default_value' => 'node',
-      '#options' => array('node' => 'Node'),
-    );
-  }
-  elseif (time_tracker_is_tracking_time($case->type) == 'comment') {
-    $form['time_sheet']['track_time_on_what'] = array(
-      '#type' => 'select',
-      '#title' => t('Track Time On'),
-      '#default_value' => 'comment',
-      '#options' => array('comment' => 'Comment'),
-    );
-  }
-
-  $form['time_sheet']['case_status_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Status'),
-    '#default_value' => $default_status,
-    '#options' => $case_status_options,
-  );
-
-  // Insert different form elements depending on the time_entry_method
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    $form['time_sheet']['duration'] = array(
-        '#title' => t('Hours'),
-        '#type' => 'textfield',
-        '#size' => '10',
-        '#required' => TRUE,
-        '#description' => t('eg. 2.5 for two and a half hours'),
-      );
-  }
-  else {
-    $form['time_sheet']['start'] = array(
-      '#title' => t('Start'),
-      '#type' => 'textfield',
-      '#size' => '10',
-      '#required' => TRUE,
-      '#description' => t('Use the format hh:mmAM/PM e.g. 12:30PM'),
-    );
-    $form['time_sheet']['end'] = array(
-      '#title' => t('End'),
-      '#type' => 'textfield',
-      '#size' => '10',
-      '#required' => TRUE,
-      '#description' => t('Use the format hh:mmAM/PM e.g. 12:30PM'),
-    );
-  }
-
-    $activities = get_active_activities_options();
-
-    $form['time_sheet']['activity'] = array(
-      '#title' => t('Activity'),
-      '#type' => 'select',
-      '#options' => $activities,
-    );
-
-  $form['time_sheet']['comment'] = array(
-    '#title' => 'Comment',
-    '#type' => 'textarea',
-    '#required' => TRUE,
-    '#weight' => 98,
-  );
-
-  $form['time_sheet']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-    '#weight' => 99,
-  );
-
-  drupal_process_form($form_id, $form, $form_state);
-
-  drupal_json(array(
-    'status'   => TRUE,
-    'data'     => theme('status_messages') . drupal_render($form),
-  ));
-
-}
-
-/**
- * TODO: What does this do? Is it the submit handler for the ahah case list
- * when javascript isn't present? Yes. But the no javascript form isn't ready yet...
- * @param $form
- * @param $form_state
- */
-function time_sheet_form_submit($form, &$form_state) {
-
-  if ($form_state['clicked_button']['#id'] == 'edit-submit') {
-    $form_state['rebuild'] = FALSE;
-    drupal_set_message(t('Form submitted'));
-  }
-  drupal_set_message(t('Form submitted'));
-  // edit-next or anything else will cause rebuild.
-  $form_state['rebuild'] = TRUE;
-
-  // Redirect to current week view
-  $form_state['redirect'] = $_SERVER['REQUEST_URI'];
-}
-
-/**
- * Validation for time sheet time submissions
- */
-function time_sheet_add_time_submit_handler_validate($form, &$form_state) {
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    if (strlen($form_state['clicked_button']['#post']['duration']) && _time_tracker_parse_duration($form_state['clicked_button']['#post']['duration']) === FALSE) {
-      form_set_error('duration', t('Invalid duration value. You may enter time fractions such as 1.25 or hour and minute values such as 2:30.'));
-    }
-  }
-  else {
-    if ($form_state['clicked_button']['#post']['start'] && !preg_match('/^[0-9]{1,2}:[0-9]{2}(AM|PM)$/', $form_state['clicked_button']['#post']['start'])) {
-      form_set_error('start', t('Start time must be in the format hh:mmAM/PM e.g. 12:30PM'));
-    } elseif ($form_state['clicked_button']['#post']['end'] && !preg_match('/^[0-9]{1,2}:[0-9]{2}(AM|PM)$/', $form_state['clicked_button']['#post']['end'])) {
-      form_set_error('end', t('End time must be in the format hh:mmAM/PM e.g. 12:30PM'));
-    }
-  }
-  if (!$form_state['clicked_button']['#post']['track_time_on_what']) {
-    form_set_error('track_time_on_what', t('Please select what you are tracking time on'));
-  }
-}
-
-/**
-* Submit handler for the second drop down.
-*/
-// TODO: this function needs cleaning up. leverage the comment api
-function time_sheet_add_time_submit_handler($form, &$form_state) {
-  // TODO: do i need to get rid of this call for user object
-  global $user;
-
-  //Some Variables for us to use
-  $time = array();
-  $comment = array();
-
-  // We don't want to execute any other submit handlers
-  unset($form_state['submit_handlers']);
-  //form_execute_handlers('submit', $form, $form_state);
-
-  // Get the case
-  $case = node_load(array('nid' => $form_state['clicked_button']['#post']['case_list']));
-
-  //$time['pid'] = $case->casetracker->pid;
-
-  $track_time_on_what = $form_state['clicked_button']['#post']['track_time_on_what'];
-
-  // Save the comment if we want to track the time on the comments
-  if ($track_time_on_what == 'comment') {
-    $form_state['rebuild'] = FALSE;
-
-    $comment['casetracker'] = get_object_vars($case->casetracker);
-    $comment['casetracker']['assign_to'] = casetracker_get_name($comment['casetracker']['assign_to']);
-
-    $comment['nid'] = $form_state['clicked_button']['#post']['case_list'];
-    $comment['uid'] = $user->uid;
-    $comment['comment'] = $form_state['clicked_button']['#post']['comment'];
-    $comment['casetracker']['case_status_id'] = $form_state['clicked_button']['#post']['case_status_id'];
-    $comment['revision_id'] = $case->vid;
-
-    $comment['cid'] = comment_save($comment);
-    preg_replace('/-.*-\d+/', '', $string);
-    //casetracker_comment($comment, 'update');
-
-    $time['cid'] = $comment['cid'];
-  }
-  elseif ($track_time_on_what == 'node') {
-    $time['note'] = $form_state['clicked_button']['#post']['comment'];
-  }
-
-  // Set the timestamp
-  $time['timestamp'] = $form_state['clicked_button']['#post']['timestamp'];
-
-  // Pull the rounding data
-  $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
-  $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
-
-  // Special handling based on the time entry method
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    $time['start'] = 0;
-    $time['end'] = 0;
-    $time['duration'] = time_tracker_round(_time_tracker_parse_duration($form_state['clicked_button']['#post']['duration']), $rounding_interval / 60, $rounding_operation);
-  }
-  elseif (variable_get('time_entry_method', 'duration') == 'interval') {
-    $time['start'] = time_tracker_round(strtotime($form_state['clicked_button']['#post']['start']), $rounding_interval * 60, $rounding_operation);
-    $time['end'] = time_tracker_round(strtotime($form_state['clicked_button']['#post']['end']), $rounding_interval * 60, $rounding_operation);
-    $time['duration'] = _time_tracker_parse_duration(convert_phptime_to_duration($time['start'], $time['end']));
-  }
-
-  // if (variable_get('time_entry_method', 'duration') == 'duration') {
-
-  // }
-  // else {
-  //   $time['start'] = $form_state['clicked_button']['#post']['start'];
-  //   $time['end'] = $form_state['clicked_button']['#post']['end'];
-  //   $time['duration'] = _time_tracker_parse_duration(convert_phptime_to_duration($time['start'], $time['end']));
-  // }
-  $time['activity'] = $form_state['clicked_button']['#post']['activity'];
-  $time['uid'] = $user->uid;
-  $time['nid'] = $form_state['clicked_button']['#post']['case_list'];
-
-  // Get the current path for redirection
-  $destination = explode('?', str_replace('destination=', '', urldecode(drupal_get_destination())));
-  $url = $destination[0];
-  $query = $destination[1];
-
-  // Redirect to current week view
-  $form_state['redirect'] = array($url, $query);
-
-  drupal_write_record('time_tracker_entry', $time);
-
-  drupal_set_message(t('Time Entry Recorded'));
-}
-
-
-/************************************************************************
- * Helper Functions
-*************************************************************************/
-
-/**
- * Function produces a list of recent cases for $user
- * in the form of options for a select form field
- *
- * @param $user
- *    The user for whom to retrieve the cases for
- */
-function _time_sheet_case_list_options($user) {
-  // Our Query
-  // A little special love for Atrium.
-  if (module_exists('atrium')) {
-    $group = spaces_get_space();
-    if ($gid = $group->group->nid) {
-      $sql = "SELECT cc.nid, n.title, n.created, cc.assign_to,
-                         cc.case_status_id, cc.pid, ccs.case_state_name,
-                         no.title AS groupname
-                  FROM {casetracker_case} AS cc
-                  JOIN {node} AS n ON n.nid = cc.nid
-                  JOIN {casetracker_case_states} AS ccs ON cc.case_status_id = ccs.csid
-                  JOIN {og_ancestry} AS oa ON oa.nid = n.nid
-                  JOIN {node} AS no ON no.nid = oa.group_nid
-                  WHERE cc.assign_to = %d
-                  AND oa.group_nid = %d
-                  AND cc.case_status_id NOT IN (6, 7, 8)
-                  ORDER BY cc.case_status_id ASC, n.created DESC";
-      // grab all cases that the user is assigned to and limit to current group
-      $case_results = db_query($sql, $user->uid, $gid);
-    }
-    else {
-      $sql = "SELECT cc.nid, n.title, n.created, cc.assign_to,
-                         cc.case_status_id, cc.pid, ccs.case_state_name,
-                         no.title AS groupname
-                  FROM {casetracker_case} AS cc
-                  JOIN {node} AS n ON n.nid = cc.nid
-                  JOIN {casetracker_case_states} AS ccs ON cc.case_status_id = ccs.csid
-                  JOIN {og_ancestry} AS oa ON oa.nid = n.nid
-                  JOIN {node} AS no ON no.nid = oa.group_nid
-                  WHERE cc.assign_to = %d
-                  AND cc.case_status_id NOT IN (6, 7, 8)
-                  ORDER BY cc.case_status_id ASC, n.created DESC";
-      // grab all cases that the user is assigned to
-      $case_results = db_query($sql, $user->uid);
-    }
-
-    // cycle through cases to create the select options array
-    $case_options = array('' => t('Select a case...'));
-    while ($case = db_fetch_object($case_results)) {
-      $project = node_load(array('nid' => $case->pid));
-
-      $case_options[$case->groupname . ' - ' . $project->title][$case->nid] = $case->title . ' (' . $case->case_state_name . ')';
-    }
-    return $case_options;
-  }
-  else {
-    $sql = "SELECT cc.nid, n.title, n.created, cc.assign_to,
-                   cc.case_status_id, cc.pid, ccs.case_state_name
-            FROM {casetracker_case} AS cc
-            JOIN {node} AS n ON n.nid = cc.nid
-            JOIN {casetracker_case_states} AS ccs ON cc.case_status_id = ccs.csid
-            WHERE cc.assign_to = %d
-            AND cc.case_status_id NOT IN (6, 7, 8)
-            ORDER BY cc.case_status_id ASC, n.created DESC";
-    // grab all cases that the user is assigned to
-    $case_results = db_query($sql, $user->uid);
-
-    // cycle through cases to create the select options array
-    $case_options = array('' => t('Select a case...'));
-    while ($case = db_fetch_object($case_results)) {
-      $project = node_load(array('nid' => $case->pid));
-
-      $case_options[$project->title][$case->nid] = $case->title . ' (' . $case->case_state_name . ')';
-    }
-    return $case_options;
-  }
-}
+<?php
+// $Id: time_sheet.module,v 1.5 2010/07/14 23:46:17 codi Exp $
+
+/**
+ * @file
+ * Enables time sheet entry for users.
+ */
+
+function time_sheet_init() {
+  drupal_add_css(drupal_get_path('module', 'time_sheet') .'/css/time_sheet.css');
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function time_sheet_permission() {
+ // if (module_exists('casetracker')) {
+ //   return array('administer time sheet', 'view time sheet entries', 'enter time on time sheet for casetracker cases');
+ // }
+ // else {
+    return array(
+      'administer time sheet' => array(
+        'title' => t('Administer Time Sheet'),
+        'description' => t('TODO: Add descriptions'),
+      ),
+      'view time sheet entries' => array(
+        'title' => t('View Time Sheet Entries'),
+        'description' => t('TODO: Add descriptions'),
+      ),
+      'add time sheet entries' => array(
+        'title' => t('Add Time Sheet Entries'),
+        'description' => t('TODO: Add descriptions'),
+      ),
+    );
+     
+ // }
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function time_sheet_help($section, $arg) {
+  switch ($section) {
+    case 'admin/help#time_sheet':
+      return t("<h2>Time Sheet</h2>
+        <p>The time sheet provides a simple weekly summary of time entries for a give user. It can be found at (user/%user_id/time_sheet). There will also be a link as a local task (tab) on the user profile page.</p>
+        <p>Settings for the Time Sheet can be found at admin/settings/time_tracker/time_sheets</p>
+        ");
+      break;
+  }
+}
+
+/**
+ * Custom Access Control
+ */
+function time_sheet_view_access($account) {
+  global $user;
+  if (is_numeric($account)) {
+    $account = user_load($account);
+  }
+  // The user is not blocked and logged in at least once.
+  if (!$account->access || !$account->status) {
+    return false;
+  }
+  if ($account && $account->uid) {
+    if ((user_access('view all time tracker entries') && user_access('view time sheet entries')) || user_access('administer users')) {
+      return true;
+    }
+    if ((user_access('view own time tracker entries') && user_access('view time sheet entries')) && $user->uid == $account->uid) {
+      return true;
+    }
+  }
+  return false;
+}
+
+/*
+ * Implementation of hook_menu().
+ *
+ * TODO: Add a menu item for administrators to view finalized time sheet entries.
+ */
+function time_sheet_menu() {
+  $items = array();
+  $items['user/%user/time_sheet'] = array(
+    'title' => 'Time Sheet',
+    'description' => 'My Time Sheet',
+    'page callback' => 'time_sheet_page',
+    'page arguments' => array(1),
+    'access callback' => 'time_sheet_view_access',
+    'access arguments' => array(1),
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['timesheet'] = array(
+    'title' => 'Time Sheet',
+    'page callback' => 'time_sheet_page',
+    'access arguments' => array('view own time tracker entries'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['time_sheet/add_time/%user'] = array(
+    'page callback' => 'time_sheet_add_time',
+    'access callback' => 'time_sheet_view_access',
+    'access arguments' => array(2),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/config/people/time_tracker/time_sheets'] = array(
+    'title' => 'Time Sheet',
+    'description' => 'Configuration settings for the time tracker time sheets.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('time_sheet_settings_form'),
+    'access arguments' => array('administer time sheet'),
+    'type' => MENU_LOCAL_TASK,
+    'parent' => 'admin/config/people/time_tracker',
+  );
+  return $items;
+}
+
+/**
+ * Implementation of hook_form().
+ */
+function time_sheet_settings_form() {
+  $form = array();
+  $form['time_sheet_settings']['time_sheet_week_start'] = array(
+    '#type' => 'select',
+    '#title' => t('First day of week'),
+    '#default_value' => variable_get('time_sheet_week_start', 'monday'),
+    '#options' => array(
+      'sunday' => t('Sunday'),
+      'monday' => t('Monday'),
+      'tuesday' => t('Tuesday'),
+      'wednesday' => t('Wednesday'),
+      'thursday' => t('Thursday'),
+      'friday' => t('Friday'),
+      'saturday' => t('Saturday'),
+    ),
+  );
+
+  $form['time_sheet_settings']['time_sheet_days_of_week'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Days of the week'),
+    '#default_value' => variable_get('time_sheet_days_of_week', array('monday', 'tuesday', 'wednesday', 'thursday', 'friday')),
+    '#options' => array(
+      'sunday' => t('Sunday'),
+      'monday' => t('Monday'),
+      'tuesday' => t('Tuesday'),
+      'wednesday' => t('Wednesday'),
+      'thursday' => t('Thursday'),
+      'friday' => t('Friday'),
+      'saturday' => t('Saturday'),
+    ),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
+ * Implementation of hook_forms()
+ */
+function time_sheet_forms($form_id, $args) {
+  if (strpos($form_id, 'time_sheet_case_list_form') !== FALSE) {
+    $forms[$form_id] = array(
+      'callback' => 'time_sheet_case_list_form',
+    );
+    return $forms;
+  }
+}
+
+/**
+ * The users time sheet page callback.
+ *
+ * @desc This callback displays a users time_sheet defaulting to the
+ * current week.
+ *
+ * @param $user
+ *    Can be a $user object, a $uid or left out entirely to load the current user
+ */
+function time_sheet_page($user = NULL) {
+  // Display a message if no nodes are set up to track time on
+  $tracking_time = FALSE;
+  foreach (node_type_get_types() as $key => $value) {
+    if (time_tracker_is_tracking_time($key)) {
+      $tracking_time = TRUE;
+      break;
+    }
+  }
+  if (!$tracking_time) {
+    drupal_set_message("No content types have been set up to track time on. This sheet will not be useful until you've set up at least one content type on which to track time. To begin tracking time, you first must enable time tracking on at least one content type. You can do so on any content type's edit page at admin/content/node-type/%content-type-name");
+  }
+  return theme('time_sheet_user_page', array('user' => $user));
+}
+
+/************************************************************************
+ * THEME FUNCTIONS
+*************************************************************************/
+
+function time_sheet_theme() {
+  return array(
+    'time_sheet_user_page' => array(
+    	'variables' => array('user' => NULL),
+    ),
+  );
+}
+
+/**
+ * Theme function for the time_sheet user page
+ *
+ * @desc This callback displays a users time_sheet defaulting to the
+ * current week.
+ *
+ * @param $user
+ *    Can be a $user object, a $uid or left out entirely to load the current user
+ *
+ * @return
+ *    A themed table of time entry data
+ */
+function theme_time_sheet_user_page($user = NULL) {
+  $user = $user['user'];
+  //Validates the user being passed in the path is a number (uid)
+  
+  if (is_numeric($user)) {
+    $user = user_load($user);
+  } // Load current user if it's null
+  elseif ($user == NULL) {
+    global $user;
+  }
+
+  // Get a start timestamp from the url parameters or set a default.
+  if (!isset($_GET['start'])) {
+    $start = time();
+  } else {
+    $start = $_GET['start'];
+  }
+
+  // Create a lookup table of time stamps for the week
+  $date_lookup = array(
+	        'sunday' => strtotime(date("Y\WW0", $start)),
+	        'monday' => strtotime(date("Y\WW1", $start)),
+                'tuesday' => strtotime(date("Y\WW2", $start)),
+                'wednesday' => strtotime(date("Y\WW3", $start)),
+                'thursday' => strtotime(date("Y\WW4", $start)),
+                'friday' => strtotime(date("Y\WW5", $start)),
+                'saturday' => strtotime(date("Y\WW6", $start))
+                );
+
+  // Get the configured days of the week
+  $days_of_week = variable_get('time_sheet_days_of_week', array('monday', 'tuesday', 'wednesday', 'thursday', 'friday'));
+  // Get the configured first day of the week
+  $first_day = variable_get('time_sheet_week_start', 'monday');
+
+  // A variable to store days at the beginning of the week
+  // to be moved to the end of the week
+  $days_at_end = array();
+  // remove items at the beginning of the week until we get to the configured $first_day
+  while (current($days_of_week) != $first_day && current($days_of_week)) {
+    $days_at_end[] = array_shift($days_of_week);
+  }
+
+  // Put the days from the beginning at the end
+  foreach($days_at_end as $day) {
+    $days_of_week[$day] = $day;	
+  }
+  // If we started the week after sunday, the days that we move to the end
+  // should be for next week, not week before.
+  foreach($days_of_week as $key => $value){
+    if(!in_array($value, $days_at_end)){
+      $days[$value] = $date_lookup[$key];	
+    }
+    else{
+      $days[$value] = strtotime('+ 1 week', $date_lookup[$key]);
+    }
+  }
+
+  // Determine the neighbouring weeks timestamps.
+  // Because of the way we structured the week, the next week will
+  // start on the 8th day after $first day. And the previous week
+  // will end 1 day before the $first day.
+  $next_week = strtotime('+ 8 days', $days[$first_day]);
+  $prev_week = strtotime('- 1 days', $days[$first_day]);
+
+  // Output the week switcher.
+  $output = '<span class="time-sheet-header">';
+  $output .= l(t('&laquo;'), $_GET['q'], array('query' => array('start' => $prev_week), 'html' => 'TRUE'));
+  $output .= ' ' . date("l, M jS", reset($days)) . ' - ' . date("l, M jS", end($days)) . ' ';
+  $output .= l(t('&raquo;'), $_GET['q'], array('query' => array('start' => $next_week), 'html' => 'TRUE'));
+  $output .= '</span>';
+
+  // Loop through days of the week pulling time entries and generating a table.
+  foreach ($days as $day => $stamp) {
+    // The header displaying the date
+    $header = array(array('data' => date("l, M jS Y", $stamp), 'colspan' => 3));
+    // Rows Variable for later theme_table-ing
+    $rows = array();
+    // Get the all the time tracker entries for the date we're on
+    
+    if(user_access('view all time tracker entries')){
+      $time_entry_results = db_select('time_tracker_entry', 'tte')
+             ->fields('tte')
+             ->condition('timestamp', array($stamp, (strtotime("+1 day", $stamp)-1), 'BEWTEEN'))
+             ->orderBy('teid')
+             ->execute();
+    }
+    else {
+      $time_entry_results = db_select('time_tracker_entry', 'tte')
+             ->fields('tte')
+             ->condition('uid', $user->uid, '=')
+             ->condition('timestamp', array($stamp, (strtotime("+1 day", $stamp)-1), 'BEWTEEN'))
+             ->orderBy('teid')
+             ->execute();	
+    }
+    $total_duration = 0;
+    // Loop throug each
+    while ($time_entry_result = $time_entry_results->fetchObject()) {
+      // Container for row data to display a time entry
+      $row = array();
+      // Load the time entry node object
+      $time_entry = node_load($time_entry_result->nid);
+      $time_user = user_load($time_entry_result->uid);
+      // Little extra love for casetracker
+      //if (module_exists('casetracker')) {
+          // Load the casetracker project node object
+      //  $project = node_load(array('nid' => $time_entry->casetracker->pid));
+      //  $project_link = ' in ' . l($project->title, 'node/' . $project->nid, array('attributes' => array('class' => 'time-sheet-project')));
+      //  $row[] = l($time_entry->title, 'node/' . $time_entry->nid, array('attributes' => array('class' => 'time-sheet-node'))) . $project_link;
+ 
+      //}
+      // The little colorful project icon next to time entries in the time_sheet
+      // And the time_entry item name. Both linked
+      
+      $row[] = l($time_entry->title, 'node/' . $time_entry->nid, array('attributes' => array('class' => 'time-sheet-node')));
+      $row[] = l($time_user->name, 'user/' . $time_user->uid, array('attributes' => array('class' => 'time-sheet-user')));
+      // The amount of time logged for this item
+      $row[] = array('data' => _time_tracker_format_hours_to_hours_and_minutes($time_entry_result->duration - $time_entry_result->deductions), 'align' => 'right');
+      // On going add-up of the total duration of time logged this week
+      $total_duration = $total_duration + ($time_entry_result->duration - $time_entry_result->deductions);
+      // Add the row to the rows
+      $rows[] = array('data' => $row);
+    }
+
+    // As long as this day has a time entry, the row array will
+    // be populated with more than 1 item
+    if (isset($row) && count($row) > 1) {
+      $row = array();
+      $row[] = array('data' => '<strong>' . t("Total hours for") . " " . date("l", $stamp) . '</strong>', 'colspan' => 2);
+      
+      $row[] = array('data' => '<strong>' . _time_tracker_format_hours_to_hours_and_minutes($total_duration) . '</strong>', 'align' => 'right');
+      $rows[] = array('data' => $row);
+    } else {
+      $row = array();
+      $row[] = array('data' => t("No time entered."), 'colspan' => 3);
+      $rows[] = array('data' => $row);
+    }
+
+    $row = array();
+    // Put the form to add a case for this day at the bottom of the day's table
+    if (user_access('add time sheet entries')) {
+      $row[] = array('data' => drupal_get_form('time_sheet_case_list_form_' . $day, $user, $day, $stamp), 'colspan' => 3);
+      $rows[] = array('data' => $row, 'id' => 'case-details-' . $day);
+    }
+
+    $table = array(
+    	'header' => $header,
+        'rows' => $rows,
+        'attributes' => array('id' => array('time-sheet-' . $day)),
+    );
+
+    // Add this day to the table
+    $output .= theme('table', $table);
+  }
+
+  return $output;
+}
+
+
+/************************************************************************
+ * CASETRACKER TIME ENTRY FORM ON TIME SHEET
+*************************************************************************/
+
+/**
+ * @desc Creates the form that provides the user with a select list of cases.
+ * Implements Drupals AHAH for ajax type form submissions.
+ *
+ * @param $form_state
+ * @param $user
+ * @param $day
+ */
+
+function time_sheet_case_list_form($form, $form_state, $user, $day, $stamp) {
+  $form = array();
+  $form['time_sheet'][$day]['#cache'] = TRUE;
+  $form['#submit'][] = 'time_sheet_add_time_submit_handler';
+
+  $form['time_sheet'][$day]['timestamp'] = array(
+    '#type' => 'hidden',
+    '#value' => $stamp,
+  );
+
+  $options = _time_sheet_case_list_options($user);
+
+  $form['time_sheet'][$day]['case_list'] = array(
+    '#type' => 'select',
+    '#title' => t('Select a task'),
+    '#options' => $options,
+    '#ajax' => array(
+      'callback' => 'time_sheet_add_time',
+      'wrapper' => 'case-form-' . $day,
+      'event' => 'change',
+    ),
+  );
+
+  // CSS hides this button.
+  // Submit handlers defined in the ahah form do not get registered
+  // This hidden button is will be passed as the 'clicked_button'
+  // When the ahah submit button is pressed
+  $form['time_sheet'][$day]['secret_submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Secret Submit'),
+    '#attributes' => array('class' => array('secret-submit')),
+  );
+
+  //$form['time_sheet'][$day]['#validate'] = 'time_sheet_add_time_submit_handler_validate';
+
+  $form['time_sheet'][$day]['case_form_wrapper'] = array(
+    '#prefix' => '<div id="case-form-' . $day . '">',
+    '#suffix' => '</div>',
+    //'#value' => '<div id="case-form-' . $day . '"></div>',
+  );
+
+  return $form;
+}
+
+
+/**
+ * Page callback For when a user selects a case to add time to from the time sheet
+ */
+function time_sheet_add_time() {
+  global $user;
+
+  // The usual AHAH stuff that needs to be here for this to work....
+  //$form_state = array('storage' => NULL, 'submitted' => FALSE);
+  //$form_build_id = $_POST['form_build_id'];
+  //$form = form_get_cache($form_build_id, $form_state);
+  //$args = $form['#parameters'];
+  //$form_id = array_shift($args);
+
+  //$form_state['post'] = $form['#post'] = $_POST;
+  //$form['#programmed'] = $form['#redirect'] = FALSE;
+
+  $form = array();
+
+  $task = node_load($form_state['post']['case_list']);
+  $project = node_load($task->field_task_project['und'][0]['nid']);
+
+  // Grab the total time spent on this ticket
+  $case_results = db_select('time_tracker_entry', 'tte')
+                    ->fields('tte')
+                    ->condition('nid', $task->nid, '=')
+                    ->condition('uid', $user->uid, '=')
+                    ->execute();
+  $total_time = 0;
+  while ($result_case = $case_results->fetchObject()) {
+    $total_time = $total_time + $result_case->duration;
+  }
+  // Grab the total time estimate for this ticket
+  //$total_estimate = db_query("SELECT estimate FROM {time_estimate_entry} WHERE nid = :nid", array(':nid' => $task->nid))->execute()->fetchField();
+                   dsm($project);
+                   dsm($task);
+  // add some case details so we know what we're dealing with
+  /*$form['time_sheet']['case_details'] = array(
+    
+    '#markup' => '<h3>' . dsm($project) .
+                   dsm($task) . '</h3><p>' . $task->teaser . '</p><p><em>' . t('Time spent by you on this case so far: ') . format_plural($total_time, '1 hour', '@count hours') . '</em></p>',
+    '#prefix' => '<div class="case-details">',
+    '#suffix' => '</div>',
+    '#weight' => -10,
+  );*/
+
+  //$case_status_options = casetracker_realm_load('status');
+  //$default_status = !empty($case->casetracker->case_status_id) ? $case->casetracker->case_status_id : variable_get('casetracker_default_case_status', key($case_status_options));
+
+
+  // We need to know what to track the time on (nodes or comments)
+  // But only if for some reason this person is tracking time on
+  // both nodes and comments
+  /*if (time_tracker_is_tracking_time($task->type) == 'both') {
+    $track_time_on_options = array(
+      'node' => 'Node',
+      'comment' => 'Comment',
+    );
+    $form['time_sheet']['track_time_on_what'] = array(
+      '#type' => 'select',
+      '#title' => t('Track Time On'),
+      '#default_value' => 'comment',
+      '#options' => $track_time_on_options,
+    );
+  }*/
+ // elseif (time_tracker_is_tracking_time($task->type) == 'node') {
+  /*  $form['time_sheet']['track_time_on_what'] = array(
+      '#type' => 'select',
+      '#title' => t('Track Time On'),
+      '#default_value' => 'node',
+      '#options' => array('node' => 'Node'),
+    );*/
+ /* }
+  elseif (time_tracker_is_tracking_time($task->type) == 'comment') {
+    $form['time_sheet']['track_time_on_what'] = array(
+      '#type' => 'select',
+      '#title' => t('Track Time On'),
+      '#default_value' => 'comment',
+      '#options' => array('comment' => 'Comment'),
+    );
+  }
+
+  $form['time_sheet']['case_status_id'] = array(
+    '#type' => 'select',
+    '#title' => t('Status'),
+    '#default_value' => $default_status,
+    '#options' => $case_status_options,
+  );
+*/
+  // Insert different form elements depending on the time_entry_method
+  if (variable_get('time_entry_method', 'duration') == 'duration') {
+    $form['time_sheet']['duration'] = array(
+        '#title' => t('Hours'),
+        '#type' => 'textfield',
+        '#size' => '10',
+        '#required' => TRUE,
+        '#description' => t('eg. 2.5 for two and a half hours'),
+      );
+  }
+  else {
+    $form['time_sheet']['start'] = array(
+      '#title' => t('Start'),
+      '#type' => 'textfield',
+      '#size' => '10',
+      '#required' => TRUE,
+      '#description' => t('Use the format hh:mmAM/PM e.g. 12:30PM'),
+    );
+    $form['time_sheet']['end'] = array(
+      '#title' => t('End'),
+      '#type' => 'textfield',
+      '#size' => '10',
+      '#required' => TRUE,
+      '#description' => t('Use the format hh:mmAM/PM e.g. 12:30PM'),
+    );
+  }
+
+    $activities = _time_tracker_get_active_activities_options();
+
+    $form['time_sheet']['activity'] = array(
+      '#title' => t('Activity'),
+      '#type' => 'select',
+      '#options' => $activities,
+    );
+
+  $form['time_sheet']['comment'] = array(
+    '#title' => 'Comment',
+    '#type' => 'textarea',
+    //'#required' => TRUE,
+    '#weight' => 98,
+  );
+
+  $form['time_sheet']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => 99,
+  );
+
+  drupal_process_form($form_id, $form, $form_state);
+  
+  return  drupal_render($form);
+}
+
+/**
+ * TODO: What does this do? Is it the submit handler for the ahah case list
+ * when javascript isn't present? Yes. But the no javascript form isn't ready yet...
+ * @param $form
+ * @param $form_state
+ */
+function time_sheet_form_submit($form, &$form_state) {
+
+  if ($form_state['clicked_button']['#id'] == 'edit-submit') {
+    $form_state['rebuild'] = FALSE;
+    drupal_set_message(t('Form submitted'));
+  }
+  drupal_set_message(t('Form submitted'));
+  // edit-next or anything else will cause rebuild.
+  $form_state['rebuild'] = TRUE;
+
+  // Redirect to current week view
+  $form_state['redirect'] = $_SERVER['REQUEST_URI'];
+}
+
+/**
+ * Validation for time sheet time submissions
+ */
+function time_sheet_add_time_submit_handler_validate($form, &$form_state) {
+  if (variable_get('time_entry_method', 'duration') == 'duration') {
+    if (strlen($form_state['clicked_button']['#post']['duration']) && _time_tracker_parse_duration($form_state['clicked_button']['#post']['duration']) === FALSE) {
+      form_set_error('duration', t('Invalid duration value. You may enter time fractions such as 1.25 or hour and minute values such as 2:30.'));
+    }
+  }
+  else {
+    if ($form_state['clicked_button']['#post']['start'] && !preg_match('/^[0-9]{1,2}:[0-9]{2}(AM|PM)$/', $form_state['clicked_button']['#post']['start'])) {
+      form_set_error('start', t('Start time must be in the format hh:mmAM/PM e.g. 12:30PM'));
+    } elseif ($form_state['clicked_button']['#post']['end'] && !preg_match('/^[0-9]{1,2}:[0-9]{2}(AM|PM)$/', $form_state['clicked_button']['#post']['end'])) {
+      form_set_error('end', t('End time must be in the format hh:mmAM/PM e.g. 12:30PM'));
+    }
+  }
+  if (!$form_state['clicked_button']['#post']['track_time_on_what']) {
+    form_set_error('track_time_on_what', t('Please select what you are tracking time on'));
+  }
+}
+
+/**
+* Submit handler for the second drop down.
+*/
+// TODO: this function needs cleaning up. leverage the comment api
+function time_sheet_add_time_submit_handler($form, &$form_state) {
+  // TODO: do i need to get rid of this call for user object
+  global $user;
+
+  //Some Variables for us to use
+  $time = array();
+  
+    $time['note'] = $form_state['input']['comment'];
+  
+
+  // Set the timestamp
+  $time['timestamp'] = $form_state['input']['timestamp'];
+
+  // Pull the rounding data
+  $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
+  $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
+
+  // Special handling based on the time entry method
+  if (variable_get('time_entry_method', 'duration') == 'duration') {
+    $time['start'] = 0;
+    $time['end'] = 0;
+    $time['duration'] = _time_tracker_round(_time_tracker_parse_duration($form_state['input']['duration']), $rounding_interval / 60, $rounding_operation);
+  }
+  elseif (variable_get('time_entry_method', 'duration') == 'interval') {
+    $time['start'] = _time_tracker_round(strtotime($form_state['input']['start']), $rounding_interval * 60, $rounding_operation);
+    $time['end'] = _time_tracker_round(strtotime($form_state['input']['end']), $rounding_interval * 60, $rounding_operation);
+    $time['duration'] = _time_tracker_parse_duration(_time_tracker_convert_phptime_to_duration($time['start'], $time['end']));
+  }
+
+  // if (variable_get('time_entry_method', 'duration') == 'duration') {
+
+  // }
+  // else {
+  //   $time['start'] = $form_state['clicked_button']['#post']['start'];
+  //   $time['end'] = $form_state['clicked_button']['#post']['end'];
+  //   $time['duration'] = _time_tracker_parse_duration(convert_phptime_to_duration($time['start'], $time['end']));
+  // }
+  $time['activity'] = $form_state['input']['activity'];
+  $time['uid'] = $user->uid;
+  $time['nid'] = $form_state['input']['case_list'];
+
+  // Get the current path for redirection
+  $destination = drupal_get_destination();
+  $destination = $destination['destination'];
+
+  $destination = explode('=', $destination);
+  $path = explode('?', $destination[0]);
+ 
+  // Redirect to current week view
+  if (isset($destination[1])){
+    $form_state['redirect'] = array($path[0],array('query' => array('start' => $destination[1])));
+  }
+  else{
+    $form_state['redirect'] = array($path[0]);	
+  }
+  drupal_write_record('time_tracker_entry', $time);
+
+  drupal_set_message(t('Time Entry Recorded'));
+}
+
+
+/************************************************************************
+ * Helper Functions
+*************************************************************************/
+
+/**
+ * Function produces a list of recent cases for $user
+ * in the form of options for a select form field
+ *
+ * @param $user
+ *    The user for whom to retrieve the cases for
+ */
+function _time_sheet_case_list_options($user) {
+    $case_options = array('' => t('Select a task...'));
+    $sql = new EntityFieldQuery();
+    $sql->entityCondition('entity_type', 'node')
+        ->entityCondition('bundle', 'task')
+        ->propertyCondition('status', 1)
+        ->fieldCondition('field_task_assigned', 'uid', $user->uid,'=')
+        ->fieldCondition('field_task_status', 'tid', 42,'!=');
+
+  $result = $sql->execute();
+   
+  if(isset($result['node'])) {
+    // cycle through cases to create the select options array
+    foreach($result['node'] as $task) {
+      $task = node_load($task->nid);
+      $project = node_load($task->field_task_project['und'][0]['nid']);
+      $case_options[$project->title][$task->nid] = $task->title;
+    }
+  }
+
+  return $case_options;
+}
\ No newline at end of file
diff --git a/time_tracker.info b/time_tracker.info
index 016426b..682f620 100644
--- a/time_tracker.info
+++ b/time_tracker.info
@@ -1,8 +1,15 @@
-; $Id: time_tracker.info,v 1.6 2010/05/28 16:30:29 codi Exp $
-name = Time Tracker
-description = Provides time tracking functionality nodes and comments.
-package = Time Tracker
-core = 6.x
-dependencies[] = views
-dependencies[] = views_calc
-dependencies[] = date_popup
\ No newline at end of file
+name = Time Tracker
+description = Provides time tracking functionality nodes and comments.
+package = Time Tracker
+core = 7.x
+dependencies[] = views
+dependencies[] = views_calc
+dependencies[] = date_popup
+dependencies[] = field
+files[] = time_tracker.admin.inc
+files[] = time_tracker.theme.inc
+files[] = time_tracker.inc
+
+files[] = views/time_tracker_views_handler_field_numeric.inc
+files[] = views/time_tracker_views_handler_field_total_duration.inc
+files[] = views/time_tracker_views_handler_filter_date.inc
diff --git a/time_tracker.install b/time_tracker.install
index 63b0f6a..c452052 100644
--- a/time_tracker.install
+++ b/time_tracker.install
@@ -1,259 +1,139 @@
-<?php
-// $Id: time_tracker.install,v 1.8 2010/06/11 21:48:22 codi Exp $
-
-/**
- * @file
- * Implementation of hook_install().
- */
-function time_tracker_schema() {
-  $schema = array();
-
-  $schema['time_tracker_entry'] = array(
-    'fields' => array(
-      'teid' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-      'nid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-      'cid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'activity' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'timestamp' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-      ),
-      'start' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'end' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'deductions' => array(
-        'type' => 'float',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'duration' => array(
-        'type' => 'float',
-        'not null' => TRUE,
-        'unsigned' => FALSE,
-        'default' => 0,
-      ),
-      'note' => array(
-        'type' => 'text',
-      ),
-      'locked' => array(
-        'type' => 'int',
-        'size' => 'tiny',
-      ),
-      'billable' => array(
-        'type' => 'int',
-        'size' => 'tiny',
-      ),
-      'billed' => array(
-        'type' => 'int',
-        'size' => 'tiny',
-      ),
-    ),
-    'primary key' => array('teid'),
-  );
-
-  $schema['time_tracker_activity'] = array(
-    'fields' => array(
-      'taid' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-      'name' => array(
-        'type' => 'varchar',
-        'length' => 100,
-      ),
-      'weight' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'status' => array(
-        'type' => 'int',
-        'size' => 'tiny',
-      ),
-    ),
-    'primary key' => array('taid'),
-  );
-
-  return $schema;
-}
-
-function time_tracker_update_6100() {
-  $return = array();
-  db_add_field($return, 'time_tracker_entry', 'pid', array('type' => 'int', 'not null' => TRUE, 'unsigned' => TRUE));
-  return $return;
-}
-
-/**
- * Adding support for start and end times rather than just durations
- */
-function time_tracker_update_6101() {
-  $return = array();
-  db_add_field($return, 'time_tracker_entry', 'start', array('type' => 'int', 'not null' => TRUE, 'unsigned' => TRUE));
-  db_add_field($return, 'time_tracker_entry', 'end', array('type' => 'int', 'not null' => TRUE, 'unsigned' => TRUE));
-  return $return;
-}
-
-/**
- * Weighs the time_tracker module so it comes before most other modules.
- */
-function time_tracker_update_6102() {
-  $return = array();
-  $return[] = $ret[] = update_sql("UPDATE {system} SET weight = -1 WHERE name = 'time_tracker'");
-  return $return;
-}
-
-/**
- * Weighs the time_tracker module so it comes before most other modules.
- */
-function time_tracker_update_6103() {
-  $return = array();
-  db_add_field($return, 'time_tracker_entry', 'note', array('type' => 'text', 'not null' => TRUE));
-  return $return;
-}
-
-/**
- * Adds locked field to time_tracker_entry
- */
-function time_tracker_update_6104() {
-  $return = array();
-  db_add_field($return, 'time_tracker_entry', 'locked', array('type' => 'int', 'size' => 'tiny'));
-  return $return;
-}
-
-/**
- * Adds status field to time_tracker_entry
- */
-function time_tracker_update_6105() {
-  $return = array();
-  db_add_field($return, 'time_tracker_activity', 'status', array('type' => 'int', 'size' => 'tiny'));
-  db_query("UPDATE {time_tracker_activity} SET status = 1 WHERE 1");
-  return $return;
-}
-
-/**
- * Adds deductions and billed fields to time_tracker_entry
- */
-function time_tracker_update_6106() {
-  $return = array();
-  db_add_field($return, 'time_tracker_entry', 'deductions', array('type' => 'float', 'not null' => TRUE, 'unsigned' => TRUE));
-  db_add_field($return, 'time_tracker_entry', 'billed', array('type' => 'int', 'size' => 'tiny'));
-  return $return;
-}
-
-/**
- * Adds deductions and billed fields to time_tracker_entry
- */
-function time_tracker_update_6107() {
-  $return = array();
-  db_drop_field($return, 'time_tracker_entry', 'pid');
-  return $return;
-}
-
-/**
- * Adds default values to columns
- */
-function time_tracker_update_6108() {
-  $return = array();
-  db_change_field($return, 'time_tracker_entry', 'cid', 'cid', array(
-    'type' => 'int',
-    'not null' => TRUE,
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'uid', 'uid', array(
-    'type' => 'int',
-    'not null' => TRUE,
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'activity', 'activity', array(
-    'type' => 'int',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'timestamp', 'timestamp', array(
-    'type' => 'int',
-    'not null' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'start', 'start', array(
-    'type' => 'int',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'end', 'end', array(
-    'type' => 'int',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'deductions', 'deductions', array(
-    'type' => 'float',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'duration', 'duration', array(
-    'type' => 'float',
-    'not null' => TRUE,
-    'unsigned' => FALSE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_entry', 'note', 'note', array(
-    'type' => 'text',
-    'default' => '',
-  ));
-  return $return;
-}
-
-/**
- * Adds default values to columns
- */
-function time_tracker_update_6109() {
-  $return = array();
-  // Type text can't have a default
-  db_change_field($return, 'time_tracker_entry', 'note', 'note', array(
-    'type' => 'text',
-  ));
-  return $return;
-}
-
-
-function time_tracker_install() {
-  drupal_install_schema('time_tracker');
-  db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", -1, 'time_tracker');
-  drupal_set_message(t("Time Tracker has been installed successfully. To begin tracking time, you first must enable time tracking on at least one content type. You can do so on any content type's edit page at admin/content/node-type/%content-type-name"));
-}
-
-function time_tracker_uninstall() {
-  drupal_uninstall_schema('time_tracker');
-}
+<?php
+/**
+ * @file
+ * Install for a basic entity - need to create the base table for our entity.
+ * This table can have as many columns as you need to keep track of
+ * entity-specific data that will not be added via attached fields.
+ * The minimum information for the entity to work is an id and an entity name.
+ */
+/**
+ * Implements hook_schema().
+ */
+function time_tracker_schema() {
+  $schema = array();
+
+  $schema['time_tracker_entry'] = array(
+    'fields' => array(
+      'teid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'nid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'cid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'uid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'activity' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'timestamp' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'start' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'end' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'deductions' => array(
+        'type' => 'float',
+        'unsigned' => TRUE,
+        'default' => 0,
+      ),
+      'duration' => array(
+        'type' => 'float',
+        'not null' => TRUE,
+        'unsigned' => FALSE,
+        'default' => 0,
+      ),
+      'note' => array(
+        'type' => 'text',
+      ),
+      'locked' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+      ),
+      'billable' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+      ),
+      'billed' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+      ),
+    ),
+    'primary key' => array('teid'),
+  );
+
+  $schema['time_tracker_activity'] = array(
+    'fields' => array(
+      'taid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => 100,
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'status' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+      ),
+    ),
+    'primary key' => array('taid'),
+  );
+
+  return $schema;
+}
+
+/**
+ * @file
+ * Implements hook_install().
+ */
+function time_tracker_install() {
+
+  db_update('system')
+    ->fields(array(
+      'weight' => -1,
+    ))
+    ->condition('name', 'time_tracker', '=')
+    ->execute();
+
+  drupal_set_message(t("Time Tracker has been installed successfully. To begin tracking time, you first must enable time tracking on at least one content type. You can do so on any content type's edit page at admin/content/node-type/%content-type-name"));
+}
+
+/*
+ * Implements hook_uninstall().
+ *
+ * At uninstall time we'll notify field.module that the entity was deleted
+ * so that attached fields can be cleaned up.
+ */
+function time_tracker_uninstall() {
+  field_attach_delete_bundle('time_tracker_entry' , 'time_entry' );
+}
diff --git a/time_tracker.module b/time_tracker.module
index 3080e49..658c9c6 100644
--- a/time_tracker.module
+++ b/time_tracker.module
@@ -1,1796 +1,1182 @@
-<?php
-// $Id: time_tracker.module,v 1.31 2010/07/22 00:32:32 codi Exp $
-
-/**
- * @file
- * Enables time tracking on nodes and comments.
- */
-
-/*
-  Define some constants
-*/
-// Default Date formats
-define('TIME_TRACKER_DEFAULT_DATE_FORMAT', 'Y-m-d H:i');
-define('TIME_TRACKER_DEFAULT_TIMESTAMP_FORMAT', 'F d, Y');
-define('TIME_TRACKER_DEFAULT_INTERVAL_FORMAT', 'h:i A - M d, Y');
-// Constants for what we are tracking time on
-define('TIME_TRACKER_BOTH', 'both');
-define('TIME_TRACKER_NODE', 'node');
-define('TIME_TRACKER_COMMENT', 'comment');
-
-// TODO: Abstract the time_entry_form and make it themeable.
-
-/************************************************************************
- * THE USUAL DRUPAL HOOKS
-*************************************************************************/
-
-/**
- * Implementation of hook_perm().
- */
-function time_tracker_perm() {
-  return array('administer time tracker', 'add time tracker entries',
-    'view all time tracker entries', 'view own time tracker entries', 'edit time tracker entries',
-    'delete time tracker entries', 'administer time entries');
-}
-
-/**
- * Implementation of hook_help().
- */
-function time_tracker_help($section, $arg) {
-  switch ($section) {
-    case 'admin/help#time_tracker':
-      return t("<h2>Time Tracker</h2>
-        <p>To begin tracking time go to the edit content type screen for any content type (admin/content/node-type/%content-type-name) and scroll to the 'Time Tracker Settings' fieldset. There, you can choose to track time either on this content type's nodes or this content type's comments. Tracking time on nodes will give you a time entry sheet and a table of time entries at the bottom of a node's content, but before the comments. Tracking time on comments will add a time entry sheet to the comment form. Keep in mind that if you choose to track time on a content type's nodes as well as comments, you will only ever see comment time entries in the comment thread, and node time entries in the time entry table. However, if you were to use views to view the time entries, you could see them all with no distinction.</p>
-        <p>We recommend deciding ahead of time whether or not you would like to track time on comments or nodes. We've found that people who just want to jot down time entries with minimal notes prefer to track time on nodes. However
-        people who like extensive notes along with their time entires, as well as the ability to thread conversations based on time entries, prefer to use comments as their vessel for tracking time.</p>
-        <p>Settings for Time Tracker can be found at admin/settings/time_tracker. They should be mostly self explanatory. We recommend, however, deciding beforehand if you wish to track time using durations (e.g. 2 hours) or time intervals (e.g. 1:00pm to 2:00pm).</p>
-        <h3>Optional Fields</h3>
-        <p>Some fields are optional. They can be enabled /disabled on the time tracker settings page:</p>
-        <ul>
-        <li>Billable:   A simple checkbox to flag the time entry as billable</li>
-        <li>Billed:     A simple checkbox to flag the time entry as billed</li>
-        <li>Deductions: This field can be used to log deductions from the total time</li>
-        </ul>
-        <h3>Activities</h3>
-        <p>Activities are specific classifications for time entries. You can administer activities at admin/settings/time_tracker/activity/list.</p>
-        <p>Disabling an activity just makes it so you can't choose it anymore. Past time entries can still reference it will display the activity name.</p>
-        <p>Deleting an activity deletes it completely from the db, thus orphaning any
-        past time entries that are referencing it.</p>
-        <h3>Permissions</h3>
-        <p>Double check your permissions before getting started:</p>
-        <ul>
-        <li><em>add time tracker entries</em><br/>
-        	  Permission to allow users to track time</li>
-        <li><em>view all time tracker entries, view own time tracker entries</em><br/>
-            Allow users to view time entries</li>
-        <li><em>edit time entries</em>	<br/>
-        	  Allow users to edit time entries</li>
-        <li><em>delete time entries</em>	<br/>
-        	  Allow users to delete time entries</li>
-        <li><em>administer time tracker</em><br/>
-        	Access the administration pages</li>
-        <li><em>administer time entries</em>	<br/>
-        	  Gives access to additional options when editing a time entry:
-        	  <ul>
-        	    <li>Allows locking of time entires (if that particular setting is on)</li>
-        	    <li>Allows editing of locked time entries</li>
-        	    <li>Allows changing of username associated with a time entry</li>
-        	 </ul>
-        </li>
-        </ul>
-        ");
-      break;
-  }
-}
-
-/**
- * Implementation of hook_menu().
- *
- */
-function time_tracker_menu() {
-  $items = array();
-
-  $items['admin/settings/time_tracker'] = array(
-    'title' => 'Time Tracker',
-    'description' => 'Adjust time tracker settings.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('time_tracker_settings_form'),
-    'access arguments' => array('administer time tracker'),
-  );
-  $items['admin/settings/time_tracker/settings'] = array(
-    'title' => 'Time Tracker',
-    'type' => MENU_DEFAULT_LOCAL_TASK,
-    'weight' => -10,
-  );
-  $items['admin/settings/time_tracker/activity/list'] = array(
-    'title' => 'Activities',
-    'description' => 'Adjust time tracker settings.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('time_tracker_activity_table_form'),
-    'access arguments' => array('administer time tracker'),
-    'type' => MENU_LOCAL_TASK,
-    'parent' => 'admin/settings/time_tracker',
-  );
-  $items['admin/settings/time_tracker/activity/delete/%'] = array(
-    'title' => 'Delete Activity',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('time_tracker_delete_activity_confirm', 5),
-    'access arguments' => array('administer time tracker'),
-  );
-  $items['time_entry/edit/%'] = array(
-    'title' => 'Time Entry',
-    'description' => 'Edit a Time Entry',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('time_tracker_time_entry_form', 1, 2),
-    'access arguments' => array('edit time tracker entries'),
-  );
-
-  return $items;
-}
-
-/**
- * What's this all about??
- */
-function time_tracker_user_page($user) {
-  $output = views_embed_view('time_tracker_user', 'default', $user->uid);
-
-  return $output;
-}
-
-/**
- * Form builder function for time tracker settings.
- */
-function time_tracker_settings_form(&$form_state) {
-
-  // Warn the user about switching between time duration and time interval time entries
-  $msg = t('Note that any entries that have been entered using the <em>duration</em> method will not have start and end times saved in the database. Switching from <em>duration</em> to <em>interval</em> will not retroactively create start and end times for past time entires.');
-
-  $form = array();
-
-  // Basic Settings
-  $form['time_tracker_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t("General Settings"),
-  );
-  $form['time_tracker_settings']['hide_comments'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Hide comments with time tracker data entirely if user does not have 'view all time tracker entries' or 'view own time tracker entries' permission"),
-    '#description' => t("Checking this setting will hide any comments that have time tracking data on them from any users without the 'view all time tracker entries' or 'view own time tracker entries' permission"),
-    '#default_value' => variable_get('hide_comments', 0),
-  );
-  $form['time_tracker_settings']['allow_locked_time_entries'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Allow locking of time entries"),
-    '#description' => t("Checking this setting will allow users with the 'administer time entries' permission to lock time entries, preventing them from being editied."),
-    '#default_value' => variable_get('allow_locked_time_entries', 0),
-  );
-  $form['time_tracker_settings']['enable_billable_field'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Enable the 'Billable' field"),
-    '#description' => t("Checking this setting will enable a checkbox to flag time entries as billable"),
-    '#default_value' => variable_get('enable_billable_field', 0),
-  );
-  $form['time_tracker_settings']['enable_billed_field'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Enable the 'Billed' field"),
-    '#description' => t("Checking this setting will enable a checkbox to flag time entries as billed"),
-    '#default_value' => variable_get('enable_billed_field', 0),
-  );
-  $form['time_tracker_settings']['enable_deductions_field'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Enable the 'Deductions' field"),
-    '#description' => t("Checking this setting will enable a text field for logging time entry deductions. An example usage of this field would be for a time entriy from 9:00am to 5:00pm with a deduction of 30 minutes for a lunch break."),
-    '#default_value' => variable_get('enable_deductions_field', 0),
-  );
-
-  // Default settings for time tracker time entry and time display fieldsets
-  $form['time_tracker_fieldset_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t("Fieldset Settings"),
-  );
-  $form['time_tracker_fieldset_settings']['time_tracker_default_collapsed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Collapse time entry form by default"),
-    '#description' => t("Checking this setting will collapse the time tracker time entry form by default"),
-    '#default_value' => variable_get('time_tracker_default_collapsed', 0),
-  );
-  $form['time_tracker_fieldset_settings']['time_entry_table_default_collapsed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Collapse time entry table by default"),
-    '#description' => t("When tracking time on nodes, checking this setting will collapse the time tracker time entry table by default"),
-    '#default_value' => variable_get('time_entry_table_default_collapsed', 0),
-  );
-
-  // Default settings for time tracker time entry and time display fieldsets
-  $form['time_tracker_userfield_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t("User Selection Field Settings"),
-  );
-  $form['time_tracker_userfield_settings']['time_tracker_user_field_type'] = array(
-    '#type' => 'radios',
-    '#title' => t('User field type'),
-    '#description' => t('The type of field for the "user" field when logging time. Only users with the "administer time tracker" permission can view the user field'),
-    '#options' => array(
-      'textfield' => t('Autocomplete textfield'),
-      'select' => t('Select box'),
-    ),
-    '#default_value' => variable_get('time_tracker_user_field_type', 'textfield'),
-  );
-
-  // Time entry settings (duration or interval)
-  $form['time_entry_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t("Time Entry Settings"),
-  );
-  $form['time_entry_settings']['time_entry_method'] = array(
-    '#type' => 'radios',
-    '#title' => t('Time Tracker Time Entry Method'),
-    '#default_value' => variable_get('time_entry_method', 'duration'),
-    '#options' => array(
-      'duration' => t('Duration'),
-      'interval' => t('Time Interval (Start and End Times)')
-    ),
-  );
-  $form['time_entry_settings']['time_entry_message'] = array(
-    '#type' => 'markup',
-    '#prefix' => '<div class="description">',
-    '#suffix' => '</div>',
-    '#value' => $msg,
-  );
-
-  // Date formats
-  $msg = 'Dates will be output using format_date(). Below, please specify PHP date format strings as required by <a href="http://php.net/manual/en/function.date.php">date()</a>. A backslash should be used before a character to avoid interpreting the character as part of a date format.';
-  $form['time_tracker_date_formats'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Time Tracker Date Formats'),
-  );
-  $form['time_tracker_date_formats']['time_entry_message'] = array(
-    '#type' => 'markup',
-    '#prefix' => '<div class="description">',
-    '#suffix' => '</div>',
-    '#value' => $msg,
-  );
-  $form['time_tracker_date_formats']['time_interval_date_format'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Time Interval Date Formats'),
-    '#description' => t('The date format for displaying time interval start and end time entries. Default is @date', array('@date' => format_date(time(), 'custom', 'h:i A - M d, Y'))),
-    '#default_value' => variable_get('time_interval_date_format', 'h:i A - M d, Y'),
-  );
-  $form['time_tracker_date_formats']['timestamp_date_format'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Timestamp Date Format'),
-    '#description' => t('The date format for displaying time entry timestamps. Usually would be displayed without time, although time information is available if desired. Default is @date', array('@date' => format_date(time(), 'custom', 'F d, Y'))),
-    '#default_value' => variable_get('timestamp_date_format', 'F d, Y'),
-  );
-
-  // Settings for time rounding
-  $form['time_rounding_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Time Rounding Settings'),
-  );
-  $form['time_rounding_settings']['time_tracker_rounding_operation'] = array(
-    '#type' => 'select',
-    '#title' => t('Rounding Operation'),
-    '#description' => t('The rounding operation to perform.'),
-    '#default_value' => variable_get('time_tracker_rounding_operation', 'auto'),
-    '#options' => array(
-      'auto' => 'Auto',
-      'up' => 'Round Up',
-      'down' => 'Round Down',
-    ),
-  );
-  $form['time_rounding_settings']['time_tracker_rounding_interval'] = array(
-    '#type' => 'select',
-    '#title' => t('Rounding Interval'),
-    '#description' => t('The interval (in minutes) to round time entries to. Choose 0 for no rounding'),
-    '#default_value' => variable_get('time_tracker_rounding_interval', 0),
-    '#options' => array(
-      0 => '0',
-      5 => '5',
-      10 => '10',
-      15 => '15',
-      20 => '20',
-      30 => '30',
-      60 => '60 (hour)',
-    ),
-  );
-  $form['time_rounding_settings']['time_tracker_rounding_message'] = array(
-    '#type' => 'checkbox',
-    '#title' => t("Display Time Rounding message on Time Entry Form"),
-    '#description' => t("Checking this setting will show a message on the time entry form, informing users that their entries will be rounded upon saving."),
-    '#default_value' => variable_get('time_tracker_rounding_message', 0),
-  );
-
-  return system_settings_form($form);
-
-}
-
-
-/**
- * Implementation of hook_views_api().
- */
-function time_tracker_views_api() {
-  return array(
-    'api' => 2,
-    'path' => drupal_get_path('module', 'time_tracker') .'/views',
-  );
-}
-
-/************************************************************************
- * BEGIN TIME TRACKER ACTIVITY CONFIG
-*************************************************************************/
-
-/**
- * Theme the activity table as a sortable list of activities.
- *
- * @ingroup themeable
- * @see time_tracker_activity_table()
- */
-function theme_time_tracker_activity_table($form) {
-  // The table headers
-  $header = array(
-    t('Activity Name'),
-    t('Enabled'),
-    t('Delete'),
-    t('Weight')
-  );
-  // Take all the form elements and format theme for theme_table
-  foreach (element_children($form['activities']) as $key) {
-    if (isset($form['activities'][$key]['name'])) {
-      // Add class to group weight fields for drag and drop.
-      $form['activities'][$key]['weight']['#attributes']['class'] = 'activity-weight';
-      // array to store row data
-      $row = array();
-      $row[] = drupal_render($form['activities'][$key]['name']);
-      $row[] = drupal_render($form['activities'][$key]['status']);
-      $row[] = drupal_render($form['activities'][$key]['delete']);
-      $row[] = drupal_render($form['activities'][$key]['weight']);
-      $rows[] = array('data' => $row, 'class' => 'draggable');
-    }
-  }
-  // Theme it as a table
-  $output = theme('table', $header, $rows, array('id' => 'activity-table'));
-  $output .= drupal_render($form['add_new_activity']);
-  // Render the form
-  $output .= drupal_render($form);
-  // Add the table drag functionality
-  drupal_add_tabledrag('activity-table', 'order', 'sibling', 'activity-weight');
-  // Return the themed activities table
-  return $output;
-}
-
-/**
- * Time tracker activities table form.
- *
- * Generates the list of activites defined by users.
- * To be themed as a sortable table (above)
- *
- * @return $form
- *    - The unrendered $form array
- */
-function time_tracker_activity_table_form() {
-
-  // Grab all the activities ordered by weight
-  $results = db_query('SELECT * FROM {time_tracker_activity} ORDER BY weight ASC');
-  // Put activities in an array
-  while ($result = db_fetch_object($results)) {
-    $activities[$result->taid] = $result;
-  }
-
-  // Setup the form
-  $form = array(
-    '#tree' => TRUE,
-    '#theme' => 'time_tracker_activity_table'
-  );
-
-  $form['add_new_activity'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Add a new Activity'),
-    '#tree' => TRUE,
-  );
-
-  $form['add_new_activity']['new_activity_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Activity Name'),
-    '#size' => 30,
-    '#description' => t('Add an activity that time can be tracked for.'),
-    '#default_value' => '',
-  );
-
-  // Loop through the activites and add them to the form.
-  if (count($activities) > 0) {
-    foreach ($activities as $activity) {
-      $form['activities'][$activity->taid]['#activity'] = (array)$activity;
-      // The activity name
-      $form['activities'][$activity->taid]['name'] = array(
-        '#type' => 'textfield',
-        '#default_value' => check_plain($activity->name),
-      );
-      // The weight (this is for the tabledrag we'll add in the theme function
-      $form['activities'][$activity->taid]['weight'] = array(
-        '#type' => 'textfield',
-        '#delta' => 10,
-        '#default_value' => $activity->weight
-      );
-      // Is this activity enabled?
-      $form['activities'][$activity->taid]['status'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('enabled'),
-        '#default_value' => $activity->status ? TRUE : FALSE,
-      );
-      // The Edit link to edit the activity
-      $form['activities'][$activity->taid]['delete'] = array(
-        '#value' => l(t('delete'), "admin/settings/time_tracker/activity/delete/$activity->taid")
-      );
-    }
-  }
-  elseif (isset($activity)) {
-    unset($form[$activity->taid]['weight']);
-  }
-
-  // The submit button for the form
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-    '#submit' => array('time_tracker_activity_table_form_submit'),
-  );
-
-  // Return the form
-  return $form;
-}
-
-/**
- * Time tracker activity form submit handler.
- *
- * @param $form
- * @param $form_state
- */
-function time_tracker_activity_table_form_submit($form, &$form_state) {
-  // If we're adding a new one
-  if ($form_state['values']['add_new_activity']['new_activity_name']) {
-    $activity = array();
-    $activity['name'] = $form_state['values']['add_new_activity']['new_activity_name'];
-    $activity['weight'] = count($form_state['values']['activities']) + 1;
-    $activity['status'] = 1;
-    drupal_write_record('time_tracker_activity', $activity);
-  }
-  if (count($form_state['values']['activities']) > 0) {
-    foreach ($form_state['values']['activities'] as $taid => $activity) {
-      // If anything has changed...
-      if (is_numeric($taid) && ($form[$taid]['#activity']['weight'] != $activity['weight'] || $form[$taid]['#activity']['status'] != $activity['status'] || $form[$taid]['#activity']['name'] != $activity['name'])) {
-        $activity['taid'] = $taid;
-        drupal_write_record('time_tracker_activity', $activity, array('taid'));
-      }
-    }
-  }
-  drupal_set_message('Activities Saved');
-}
-
-/**
- * Form builder function for module time tracker activities.
- */
-function time_tracker_delete_activity_confirm(&$form_state, $taid) {
-
-  $form = array();
-
-  if ($taid) {
-    $form['taid'] = array(
-      '#type' => 'value',
-      '#default_value' => $taid,
-    );
-    $question = t('Are you sure you want to delete the activity: !activity_name', array('!activity_name' => get_activity_name($taid)));
-    return confirm_form($form, $question, 'admin/settings/time_tracker/activity/list');
-  }
-  else {
-    return $form['msg']['#value'] = 'No Activity ID passed in.';
-  }
-}
-
-/**
- * Time tracker activity form submit handler.
- *
- * @param $form
- * @param $form_state
- */
-function time_tracker_delete_activity_confirm_submit($form, &$form_state) {
-  $form_state['redirect'] = 'admin/settings/time_tracker/activity/list';
-  db_query('DELETE FROM {time_tracker_activity} WHERE taid = ' . $form_state['values']['taid']);
-  drupal_set_message(t('Activity %name Deleted', array('%name' => $form_state['values']['name'])));
-}
-
-/************************************************************************
-  BEGIN ACTUAL TIME TRACKER CODE -- DRUPAL HOOKS
-*************************************************************************/
-
-/**
- * Implementation of hook_form_alter().
- *
- * Adds the options for tracking time to the
- */
-function time_tracker_form_alter(&$form, $form_state, $form_id) {
-  // what are we tracking time on?
-  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
-    $form['time_tracker'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Time Tracker settings'),
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE,
-    );
-    $form['time_tracker']['time_tracker_nodes'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Track time on this content types nodes'),
-      '#default_value' => variable_get('time_tracker_nodes_' . $form['#node_type']->type, 0),
-      '#description' => t('Track time on this content types nodes.'),
-    );
-    $form['time_tracker']['time_tracker_comments'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Track time on this content types comments'),
-      '#default_value' => variable_get('time_tracker_comments_' . $form['#node_type']->type, 0),
-      '#description' => t('Track time on this content types comments.'),
-    );
-  }
-
-  // if this is a comment form and we're tracking time on it.
-  if ($form_id == 'comment_form' && user_access('add time tracker entries')) {
-
-    $node = node_load($form['nid']['#value']);
-
-    if (variable_get('time_tracker_comments_' . $node->type, 0)) {
-      $form = array_merge($form, time_tracker_time_entry_form(NULL, 'comment', $form['cid']['#value']));
-    }
-  }
-
-}
-
-/**
- * Implementation of hook_nodeapi().
- */
-function time_tracker_nodeapi(&$node, $op) {
-  switch ($op) {
-    case 'view':
-      if (user_access('view all time tracker entries') || user_access('view own time tracker entries')) {
-        // init total time
-        $total_time = 0;
-        // If case tracker exists then we can check if it's a project
-        if (module_exists('casetracker') && casetracker_is_project($node->type)) {
-          $case_results = db_query("SELECT * FROM {casetracker_case} WHERE pid = %d", $node->nid);
-
-          while ($case = db_fetch_object($case_results)) {
-            $time_results = db_query("SELECT * FROM {time_tracker_entry} WHERE nid = %d", $case->nid);
-
-            while ($time = db_fetch_object($time_results)) {
-              $total_time = $total_time + ($time->duration - $time->deductions);
-            }
-          }
-          if ($total_time > 0) {
-            $node->content['time_tracker_summary'] = array(
-              '#value' => theme('time_tracker_summary', $total_time),
-              '#weight' => -5,
-            );
-          }
-
-        }
-        else {
-
-          $total_time = time_tracker_get_total_logged_time($node->nid);
-
-          if ($total_time > 0) {
-            $node->content['time_tracker_summary'] = array(
-              '#value' => theme('time_tracker_summary', $total_time),
-              '#weight' => -5,
-            );
-          }
-        }
-
-        // display the time tracking form for nodes here.
-        if (variable_get('time_tracker_nodes_' . $node->type, 0)) {
-          // Store time entries from nodes
-          $node_time_entries = array();
-          $sql = "SELECT * FROM {time_tracker_entry} AS t
-                  WHERE nid = %d AND cid = 0
-                  ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
-          // Get the entries associated with this node
-          $resource = db_query($sql, $node->nid);
-          // Store the db objects in an array for theme function
-          while ($time_entry = db_fetch_object($resource)) {
-            $node_time_entries[] = $time_entry;
-          }
-          $node->content['time_tracker'] = array(
-            '#value' => theme('time_tracker_time_entry_table', $node_time_entries) .
-                        (user_access('add time tracker entries') ? drupal_get_form('time_tracker_time_entry_form', 'node', $node->nid) : ''),
-            '#weight' => 51,
-          );
-        }
-      }
-    break;
-
-    case 'delete':
-      db_query("DELETE FROM {time_tracker_entry} WHERE nid = %d", $node->nid);
-      db_query("DELETE FROM {time_tracker_timer} WHERE nid = %d", $node->nid);
-    break;
-
-    case 'insert':
-    case 'update':
-
-    break;
-  }
-}
-
-/**
- * Implementation of hook_comment().
- *
- * TODO: previews aren't showing any time_tracker data.
- */
-function time_tracker_comment(&$comment, $op) {
-
-  switch ($op) {
-    case 'view':
-    // We only want to show time tracker data if user has permission
-      if (user_access('view all time tracker entries') || (user_access('view own time tracker entries') && $GLOBALS['user']->uid == $comment->uid)) {
-        // If this is a preview we won't have a cid yet.
-        if (empty($comment->cid)) {
-          $time_tracker_data = (object)$comment->time_tracker;
-          $node = node_load($comment->nid);
-        }
-        else {
-          $results = db_query("SELECT * FROM {time_tracker_entry} WHERE cid = %d", $comment->cid);
-          while ($result = db_fetch_object($results)) {
-            $time_tracker_data = $result;
-          }
-        }
-        if (is_object($time_tracker_data)) {
-          // This will flag the comment so it can be hidden
-          // hide flag is triggered in the preprocess function below
-          $comment->status = 2;
-        }
-        $comment->comment = theme('time_tracker_comment', $time_tracker_data) . $comment->comment;
-      }
-    break;
-
-    case 'validate':
-      $form_state['values'] = $comment;
-      time_tracker_time_entry_validate(NULL, $form_state);
-
-    break;
-
-    case 'insert':
-    case 'update':
-      $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
-      $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
-      // Round the deductions if necessary
-      $comment['deductions'] = isset($comment['deductions']) ? time_tracker_round(_time_tracker_parse_duration($comment['deductions']), $rounding_interval / 60, $rounding_operation) : NULL;
-      // Check First if we are tracking by duration or time interval
-      if (variable_get('time_entry_method', 'duration') == 'duration') {
-        $duration = time_tracker_round(_time_tracker_parse_duration($comment['duration']), $rounding_interval / 60, $rounding_operation);
-        if ($duration > 0) {
-          $comment['duration'] = $duration;
-          $comment['timestamp'] = strtotime($comment['time']);
-          unset($comment['time']);
-          // Update or create the time entry
-          return drupal_write_record('time_tracker_entry', $comment, $comment['teid'] ? 'teid' : array());
-        }
-        elseif ($comment['teid']) {
-          // No duration, but there WAS duration information -- someone wants
-          // to remove the time entry!
-          db_query("DELETE FROM {time_tracker_entry} WHERE teid = %d", $comment['teid']);
-        }
-      }
-      elseif (variable_get('time_entry_method', 'duration') == 'interval') {
-        if (strlen($comment['start']) && strlen($comment['end'])) {
-          $comment['start'] = $comment['timestamp'] = time_tracker_round(strtotime($comment['start']), $rounding_interval * 60, $rounding_operation);
-          $comment['end'] = time_tracker_round(strtotime($comment['end']), $rounding_interval * 60, $rounding_operation);
-          //Do we make the duration into a timestamp now??
-          $comment['duration'] = _time_tracker_parse_duration(convert_phptime_to_duration( $comment['start'], $comment['end']));
-          return drupal_write_record('time_tracker_entry', $comment, $comment['teid'] ? 'teid' : array());
-        }
-        elseif ($comment['teid']) {
-          // No duration, but there WAS duration information -- someone wants
-          // to remove the time entry!
-          db_query("DELETE FROM {time_tracker_entry} WHERE teid = %d", $comment['teid']);
-        }
-      }
-
-    break;
-
-    case 'delete':
-      db_query("DELETE FROM {time_tracker_entry} WHERE cid = %d", $comment->cid);
-    break;
-  }
-}
-
-/***********************************************************************
- * TIME TRACKER -- TIME ENTRY FORM
- ***********************************************************************/
-
-/**
- * Defines the time entry form
- *
- * NOTE: This was a first step in refactoring this form into it's own function
- *
- * @param $type
- *    The type of time entry form to show. Choose from:
- *    'node':     Form when tracking time on nodes
- *    'edit':     Form when editing time entries. Specifically applies to
- *                time entries tracked on nodes. Comment time entry editing
- *                is done when editing the comment
- *    'comment':  Form when tracking time on comments
- *
- * @param $id
- *    Depending on the type:
- *    'node' => nid (node id)
- *    'edit' => teid (time entry id)
- *    'comment => cid (comment id)
- *
- */
-function time_tracker_time_entry_form($form_state, $type = 'node', $id = 0) {
-  // Current user
-  global $user;
-
-  // Our base css for the form to put form elements side by side
-  drupal_add_css(drupal_get_path('module', 'time_tracker') .'/css/time_tracker.css');
-
-  // Our list of possible activities formatted as an option list for the select drop down
-  $activities = get_active_activities_options();
-
-  // Assume it isn't locked for now.
-  $lock = FALSE;
-
-  // The time tracker time entry form fieldset
-  $form['time_tracker'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Time Tracker'),
-    '#collapsible' => TRUE,
-    '#collapsed' => variable_get('time_tracker_default_collapsed', 0),
-    '#weight' => -9,
-  );
-
-  // Display a message about the rounding if it's on and messages are set to display
-  if (variable_get('time_tracker_rounding_message', 0) && variable_get('time_tracker_rounding_interval', 0)) {
-    $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
-    $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
-    if ($rounding_operation == 'auto') {
-      $rounding_operation = 'rounded';
-    }
-    else {
-      $rounding_operation = 'rounded ' . $rounding_operation;
-    }
-    $msg = t('Time rounding is ON. Time will be !rounded to the nearest !minutes minute interval.', array('!rounded' => $rounding_operation, '!minutes' => $rounding_interval));
-    // Add it to the time_tracker fieldset
-    $form['time_tracker']['#description'] = $msg;
-  }
-
-  // If we are editing a comment...
-  if ($type == 'comment' && $id) {
-    // Gotta grab the comment's info if we're editing an old comment
-    $results = db_query("SELECT * FROM {time_tracker_entry} WHERE cid = %d", $id);
-    $time_tracker_data = db_fetch_object($results);
-    // Need a comment id for comment tracking
-    $form['cid'] = array(
-      '#type' => 'value',
-      '#value' => $time_tracker_data->cid ? $time_tracker_data->cid : $id,
-    );
-  }
-  elseif ($type == 'edit' && $id) {
-    $results = db_query("SELECT * FROM {time_tracker_entry} WHERE teid = %d", $id);
-    $time_tracker_data = db_fetch_object($results);
-    // The node this time entry belongs to
-    $form['nid'] = array(
-      '#type' => 'value',
-      '#value' => $time_tracker_data->nid,
-    );
-    if (user_access('delete time tracker entries') || user_access('administer time entries')) {
-      // A delete button
-      $form['time_tracker']['delete'] = array(
-        '#type' => 'submit',
-        '#value' => t('Delete'),
-        '#weight' => 9,
-        '#submit' => array('time_tracker_time_entry_delete'),
-      );
-    }
-    // We will redirect to the node this time entry belongs to once edited
-    $form['#redirect']['redirect'] = 'node/' . $time_tracker_data->nid;
-  }
-  elseif ($type == 'node' && $id) {
-    // Just need the nid for node time entries
-    $form['nid'] = array(
-      '#type' => 'value',
-      '#value' => $id,
-    );
-  }
-
-  // If there is a time tracker entry data object
-  if ($time_tracker_data) {
-    // If it's an existing time entry, we need the teid
-    $form['teid'] = array(
-      '#type' => 'value',
-      '#value' => $time_tracker_data->teid,
-    );
-    if (variable_get('allow_locked_time_entries', 0)) {
-      if (user_access('administer time entries')) {
-        $form['time_tracker']['locked'] = array(
-          '#title' => t('Locked'),
-          '#type' => 'checkbox',
-          '#description' => 'Lock this time entry, preventing further editing',
-          '#default_value' => $time_tracker_data->locked ? TRUE : FALSE,
-          '#weight' => 6,
-        );
-      }
-      elseif ($time_tracker_data->locked) {
-        // We will use $lock throughout the form to determine whether or not
-        // we should be hiding the form elements. We want to keep them intact,
-        // however for the comments form by making their type 'value' because
-        // we don't want to prevent the saving of comment forms directly, we
-        // just want to prevent the changing of time entry data.
-        $lock = TRUE;
-        $msg = 'This time entry is locked from editing.';
-        $form['time_tracker']['locked_msg'] = array(
-          '#value' => $msg,
-        );
-        unset($form['time_tracker']['delete']);
-      }
-    }
-  }
-
-  $user_submit = user_load($time_tracker_data->uid);
-
-  // Auto complete/select user reference but only if you have permission
-  $form['time_tracker']['username'] = array(
-    '#title' => t('User'),
-    '#access' => user_access('administer time entries'),
-    '#type' => $lock ? 'value' : variable_get('time_tracker_user_field_type', 'textfield'),
-    '#weight' => 0,
-    '#default_value' => $user_submit->name ? $user_submit->name : $user->name,
-  );
-
-  if(variable_get('time_tracker_user_field_type', 'textfield') == 'select'){
-    if (module_exists('casetracker')) {
-      $options = drupal_map_assoc(casetracker_user_options());
-    } else {
-      $users = db_query("SELECT uid, name FROM {users} WHERE uid > 0");
-
-      while ($user_info = db_fetch_array($users)) {
-        $options[$user_info['uid']] = $user_info['name'];
-      }
-
-    }
-    array_shift($options);
-    $form['time_tracker']['username'] += array('#options' => $options);
-    $form['time_tracker']['username']['#weight'] -= 1;
-  }
-  else {
-    $form['time_tracker']['username'] += array(
-      '#autocomplete_path' => 'user/autocomplete',
-      '#size' => '15',
-    );
-  }
-
-  // The activity choser
-  $form['time_tracker']['activity'] = array(
-    '#title' => t('Activity'),
-    '#type' => $lock ? 'value' : 'select',
-    '#weight' => 0,
-    '#options' => $activities,
-    '#default_value' => $time_tracker_data->activity,
-  );
-
-  // Add some javascript and css for the datepicker
-  if (module_exists('jquery_ui')) {
-    jquery_ui_add(array('ui.datepicker'));
-    drupal_add_js(drupal_get_path('module', 'time_tracker') .'/js/datepicker.settings.js');
-    // $js_settings['timeTracker'] = array(
-    //   'timeTrackerDateFormat' => datepicker_format_replacements(variable_get('timestamp_date_format', 'F d, Y')),
-    // );
-    // drupal_add_js($js_settings, 'setting');
-    drupal_add_css(drupal_get_path('module', 'jquery_ui') .'/jquery.ui/themes/default/ui.datepicker.css');
-  }
-
-  // Insert different form elements depending on the time_entry_method
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    $format = variable_get('timestamp_date_format', 'F d, Y');
-    $form['time_tracker']['time_entry']['time'] = array(
-      '#title' => t('Date'),
-      '#type' => $lock ? 'value' : 'date_popup',
-      '#date_format' => $format,
-      '#date_label_position' => 'within',
-      '#size' => 20,
-      '#weight' => 0,
-      '#default_value' => empty($time_tracker_data->timestamp) ? date(TIME_TRACKER_DEFAULT_DATE_FORMAT, time()) : date(TIME_TRACKER_DEFAULT_DATE_FORMAT, $time_tracker_data->timestamp),
-    );
-    $form['time_tracker']['time_entry']['duration'] = array(
-      '#title' => t('Hours'),
-      '#type' => $lock ? 'value' : 'textfield',
-      '#size' => '10',
-      '#weight' => 1,
-      '#default_value' => $time_tracker_data->duration ? format_hours_to_hours_and_minutes($time_tracker_data->duration, TRUE) : $time_tracker_data->duration,
-      '#description' => t('eg. 2.5 or 2:30 for two and a half hours'),
-    );
-  }
-  else { // Time entry method is 'interval'
-    $format = variable_get('time_interval_date_format', 'h:i A - M d, Y');
-    $form['time_tracker']['time_entry']['prefix'] = array(
-      '#value' => '<div class="time_entry">',
-      '#weight' => 0,
-    );
-    $form['time_tracker']['time_entry']['start'] = array(
-      '#title' => t('Start'),
-      '#type' => $lock ? 'value' : 'date_popup',
-      '#default_value' => $time_tracker_data->start ? date(TIME_TRACKER_DEFAULT_DATE_FORMAT, $time_tracker_data->start) : '',
-      '#date_format' => $format,
-      '#date_label_position' => 'within',
-      '#weight' => 1,
-    );
-    $form['time_tracker']['time_entry']['end'] = array(
-      '#title' => t('End'),
-      '#type' => $lock ? 'value' : 'date_popup',
-      '#default_value' => $time_tracker_data->end ? date(TIME_TRACKER_DEFAULT_DATE_FORMAT, $time_tracker_data->end) : '',
-      '#date_format' => $format,
-      '#date_label_position' => 'within',
-      '#weight' => 2,
-    );
-    $form['time_tracker']['time_entry']['suffix'] = array(
-      '#value' => '</div>',
-      '#weight' => 3,
-    );
-    // If duration data exists already we post a note to the user
-    if ($time_tracker_data->duration && !($time_tracker_data->end) && !($time_tracker_data->start)) {
-      $form['time_tracker']['duration_msg'] = array(
-        '#prefix' => '<div class="description"><em>',
-        '#value' => t("A duration value exists for this time entry, but no Start and End time. <br/> Saving this entry with a Start and End time will overwrite the duration<br/> Logged Duration: <b>!duration</b>", array('!duration' => format_hours_to_hours_and_minutes($time_tracker_data->duration))),
-        '#suffix' => '</em></div>',
-        '#weight' => 4,
-      );
-    }
-  }
-
-  // Deductions
-  if (variable_get('enable_deductions_field', 0)) {
-    $form['time_tracker']['time_entry']['deductions'] = array(
-      '#title' => t('Deductions'),
-      '#type' => $lock ? 'value' : 'textfield',
-      '#size' => '10',
-      '#weight' => 3,
-      '#default_value' => $time_tracker_data->deductions ? format_hours_to_hours_and_minutes($time_tracker_data->deductions, TRUE) : $time_tracker_data->deductions,
-      '#description' => t('eg. 2.5 or 2:30 for two and a half hours'),
-    );
-  }
-
-  // Billable and Billed fields
-  if (variable_get('enable_billable_field', 0)) {
-    $form['time_tracker']['billable'] = array(
-      '#title' => t('Billable'),
-      '#type' => $lock ? 'value' : 'checkbox',
-      '#size' => '10',
-      '#weight' => 6,
-      '#default_value' => $time_tracker_data->billable,
-    );
-  }
-  if (variable_get('enable_billed_field', 0)) {
-    $form['time_tracker']['billed'] = array(
-      '#title' => t('Billed'),
-      '#type' => $lock ? 'value' : 'checkbox',
-      '#size' => '10',
-      '#weight' => 6,
-      '#default_value' => $time_tracker_data->billed,
-    );
-  }
-
-  // If this isn't meant to track time on a comment, we need a submit button and notes field
-  if ($type != 'comment') {
-    $form['time_tracker']['note'] = array(
-      '#title' => t('Note'),
-      '#type' => $lock ? 'value' : 'textarea',
-      '#weight' => 7,
-      '#rows' => 2,
-      '#resizable' => FALSE,
-      '#default_value' => $time_tracker_data->note,
-    );
-    if (!$lock) {
-      $form['time_tracker']['submit'] = array(
-        '#type' => 'submit',
-        '#value' => t('Save'),
-        '#weight' => 8,
-      );
-    }
-    $form['#validate'] = array('time_tracker_time_entry_validate');
-    $form['#submit'] = array('time_tracker_time_entry_submit');
-  }
-
-  // // If we're allowing for locked time entries,
-  // // ensure user has permissions to edit locked entries
-  // if (variable_get('allow_locked_time_entries', 0) && $time_tracker_data->locked && !user_access('administer time entries')) {
-  //   // No go, redirect
-  //   drupal_goto('node/' . $time_tracker_data->nid);
-  //   return;
-  // }
-
-  return $form;
-}
-
-function time_tracker_time_entry_validate($form, &$form_state) {
-  $values = $form_state['values'];
-  // Check First if we are tracking by duration or time interval
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    // If a duration is set, but no date
-    if (strlen($values['duration']) && !strlen($values['time'])) {
-      form_set_error('time', t('Invalid Date Value. You must also set a date if you wish to log time'));
-    }
-    // If a duration is set, but it is invalid
-    if (strlen($values['duration']) && _time_tracker_parse_duration($values['duration']) === FALSE) {
-      form_set_error('duration', t('Invalid duration value. You may enter time fractions such as 1.25 or hour and minute values such as 2:30.'));
-    }
-  }
-  elseif (variable_get('time_entry_method', 'duration') == 'interval') {
-    // If there is no start time, but there is an end time
-    if (!strlen($values['start']) && strlen($values['end'])) {
-      form_set_error('start][date', t('Enter an End time, or no time at all'));
-    }
-    // If there is no end time, but there is an start time
-    if (!strlen($values['end']) && strlen($values['start'])) {
-      form_set_error('end][date', t('Enter a Start time, or no time at all'));
-    }
-      // Make sure From date is before To Date
-    if (strlen($values['start']) && strlen($values['end'])) {
-      $start = strtotime($values['start']);
-      $end = strtotime($values['end']);
-      if ($start >= $end) {
-        form_set_error('start][date', t('Invalid interval value. Start time must come before End time'));
-      }
-    }
-  }
-  elseif (isset($values['deductions'])) {
-    // If a duration is set, but it is invalid
-    if (strlen($values['deductions']) && _time_tracker_parse_duration($values['deductions']) === FALSE) {
-      form_set_error('duration', t('Invalid deductions value. You may enter time fractions such as 1.25 or hour and minute values such as 2:30.'));
-    }
-  }
-}
-
-function time_tracker_time_entry_submit($form, &$form_state) {
-
-  // Our array for drupal_write_record
-  $time = array();
-  // Our submitted form values
-  $values = $form_state['values'];
-  // Need a user
-  $user = user_load(array('name' => $values['username']));
-  // If this is an existing time entry...
-  $time['teid'] = $values['teid'];
-  // Store the rounding data
-  $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
-  $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
-
-  // Special handling based on the time entry method
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    $time['start'] = 0;
-    $time['end'] = 0;
-    $time['duration'] = time_tracker_round(_time_tracker_parse_duration($values['duration']), $rounding_interval / 60, $rounding_operation);
-    $time['timestamp'] = strtotime($values['time']);
-  }
-  elseif (variable_get('time_entry_method', 'duration') == 'interval') {
-    $time['start'] = time_tracker_round(strtotime($values['start']), $rounding_interval * 60, $rounding_operation);
-    $time['end'] = time_tracker_round(strtotime($values['end']), $rounding_interval * 60, $rounding_operation);
-    $time['timestamp'] = $time['start'];
-    $time['duration'] = _time_tracker_parse_duration(convert_phptime_to_duration($time['start'], $time['end']));
-  }
-
-  // The rest of the time entry
-  $time['activity'] = $values['activity'];
-  $time['uid'] = $user->uid;
-  $time['nid'] = $values['nid'];
-  $time['note'] = $values['note'];
-
-  // If locked was in the form use it
-  $time['locked'] = isset($values['locked']) ? $values['locked'] : FALSE;
-  // If billable was in the form use it
-  $time['billable'] = isset($values['billable']) ? $values['billable'] : NULL;
-  // If billed was in the form use it
-  $time['billed'] = isset($values['billed']) ? $values['billed'] : NULL;
-  // If billed was in the form use it
-  $time['deductions'] = isset($values['deductions']) ? time_tracker_round(_time_tracker_parse_duration($values['deductions']), $rounding_interval / 60, $rounding_operation) : NULL;
-
-  // Update the db and send a message to the user
-  drupal_write_record('time_tracker_entry', $time, $time['teid'] ? 'teid' : array());
-
-  // Message to the user
-  if ($rounding_interval) {
-    if ($rounding_operation == 'auto') {
-      $rounding_operation = 'rounded';
-    }
-    else {
-      $rounding_operation = 'rounded ' . $rounding_operation;
-    }
-    drupal_set_message(t('Time Entry Recorded. Time was !rounded to the nearest !minutes mintues', array('!rounded' => $rounding_operation, '!minutes' => $rounding_interval)));
-  }
-  else {
-    drupal_set_message(t('Time Entry Recorded'));
-  }
-}
-
-function time_tracker_time_entry_delete($form, &$form_state) {
-  if ($form_state['values']['teid']) {
-    db_query("DELETE FROM {time_tracker_entry} WHERE teid = %d", $form_state['values']['teid']);
-  }
-  drupal_set_message(t('Time Entry Deleted'));
-}
-
-
-/***********************************************************************
- * THEME FUNCTIONS
- ***********************************************************************/
-
-/**
- * Implementation of hook_theme().
- */
-function time_tracker_theme() {
-  return array(
-    'time_tracker_time_entry_table' => array(),
-    'time_tracker_comment' => array(),
-    'time_tracker_project_summary' => array(), // not in use
-    'time_tracker_summary' => array(),
-    'time_tracker_activity_table' => array(
-      'arguments' => array('form' => array()),
-    ),
-  );
-}
-
-/**
- * Theme function for showing time entries on nodes
- *
- * @param $time_entries
- *    An array of time entry database objects.
- *    Time entry object contains properties:
- *      $obj->teid: The time entry id
- *      $obj->nid: The node id this time entry is attached to
- *      $obj->uid: The user id to whom this time entry belongs
- *      $obj->cid: If applicable, the comment id for this time entry
- *      $obj->pid: If applicable, the casetracker project id for this time entry (removed)
- *      $obj->activity: The time entry Activity
- *      $obj->timestamp: The unix timestamp of when this time entry was dated
- *      $obj->start: If tracking time by interval, the start time of the entry
- *      $obj->end: If tracking time by interval, the end time of the entry
- *      $obj->duration: The time entry duration in HOURS
- *      $obj->note: Any notes about the time entry (Empty for time tracked on comments)
- *      $obj->billable: Whether this is billable or not (0 => no, 1 => yes)
- *      $obj->locked: Whether this entry has been locked, requires extra permissions
- */
-function theme_time_tracker_time_entry_table($time_entries) {
-  // Add the css for some base theming of the table
-  drupal_add_css(drupal_get_path('module', 'time_tracker') .'/css/time_tracker.css');
-  //Some Variables to make this happen
-  $rows[] = array();
-  //Setting up the table headers
-  $header = array(
-    array('data' => t('User')),
-    array('data' => t('Activity')),
-  );
-  // If the deductions field is on
-  if (variable_get('enable_deductions_field', 0)) {
-    $header[] = array('data' => t('Duration'));
-    $header[] = array('data' => t('Deductions'));
-    $header[] = array('data' => t('Total'));
-  }
-  else {
-    $header[] = array('data' => t('Duration'));
-  }
-  // These columns are always there
-  $header[] = array('data' => t('Time'));
-  $header[] = array('data' => t('Note'));
-  // Only show the billed and billable fields if they're on
-  if (variable_get('enable_billable_field', 0)) {
-    $header[] = array('data' => t('Billable'));
-  }
-  if (variable_get('enable_billed_field', 0)) {
-    $header[] = array('data' => t('Billed'));
-  }
-  // Need to add the operations column if permissions allow it
-  if (user_access('edit time tracker entries') || user_access('administer time entries')) {
-   $header[] = array('data' => t('Ops'));
-  }
-  //Loop through the time entries and add them to the table
-  foreach ($time_entries as $time_entry) {
-    if (user_access('view all time tracker entries') || (user_access('view own time tracker entries') && $GLOBALS['user']->uid == $time_entry->uid)) {
-      // Special formatting for duration based time entries
-      if (variable_get('time_entry_method', 'duration') == 'duration') {
-        $time = format_date($time_entry->timestamp, 'custom', variable_get('timestamp_date_format', 'F d, Y'));
-      }
-      // Special formatting for interval based time entries
-      elseif (variable_get('time_entry_method', 'duration') == 'interval') {
-        if ($time_entry->start && $time_entry->end) {
-          $time = '' . format_date($time_entry->start, 'custom', variable_get('time_interval_date_format', 'h:i A - M d, Y')) . '<br/>' . format_date($time_entry->end, 'custom', variable_get('time_interval_date_format', 'h:i A - M d, Y'));
-        }
-        else {
-          $time = format_date($time_entry->timestamp, 'custom', variable_get('timestamp_date_format', 'F d, Y')) . '<br/>Entered as Duration';
-        }
-      }
-      // Populate the row
-      $row = array(//row
-        'data' => array( //row data
-          array( //Cell1
-            'data' => user_load($time_entry->uid)->name,
-            'class' => 'time_entry_username',
-          ),
-          array( //Cell2
-            'data' => get_activity_name($time_entry->activity),
-            'class' => 'time_entry_activity',
-          ),
-          array( //Cell3
-            'data' => format_hours_to_hours_and_minutes($time_entry->duration),
-            'class' => 'time_entry_duration',
-          ),
-        ),
-        'class' => '', //row class
-      );//endrow
-      if (variable_get('enable_deductions_field', 0)) {
-        $row['data'][] = array( //Cell6
-   	      'data' => format_hours_to_hours_and_minutes($time_entry->deductions),
-   	      'class' => 'time_entry_deductions',
-   	    );
-   	    $row['data'][] = array( //Cell6
-   	      'data' => format_hours_to_hours_and_minutes($time_entry->duration - $time_entry->deductions),
-   	      'class' => 'time_entry_total',
-   	    );
-      }
-      // The time field is not optional
-      $row['data'][] = array( //Cell4
-        'data' => $time,
-        'class' => 'time_entry_time',
- 	    );
- 	    // The note field is not optional
- 	    $row['data'][] = array( //Cell5
-        'data' => $time_entry->note,
-        'class' => 'time_entry_note',
- 	    );
-      if (variable_get('enable_billable_field', 0)) {
-        $row['data'][] = array( //Cell6
-   	      'data' => $time_entry->billable ? t('Yes') : t('No'),
-   	      'class' => 'time_entry_billable',
-   	    );
-      }
-      if (variable_get('enable_billed_field', 0)) {
-        $row['data'][] = array( //Cell6
-   	      'data' => $time_entry->billed ? t('Yes') : t('No'),
-   	      'class' => 'time_entry_billed',
-   	    );
-      }
-      if (user_access('edit time tracker entries') || user_access('administer time entries')) {
-        // If entry is locked and user does not have proper permissions
-     	  if (variable_get('allow_locked_time_entries', 0) && $time_entry->locked && !user_access('administer time entries')) {
-     	    $row['data'][] = array( //Cell6
-     	      'data' => t('locked'),
-     	      'class' => 'time_entry_edit',
-     	    );
-     	  }
-        else {
-          $row['data'][] = array( //Cell6
-            'data' => l(t('edit'), 'time_entry/edit/' . $time_entry->teid),
-            'class' => 'time_entry_edit',
-          );
-        }
-      }
-      $rows[] = $row;
-    }
-  }
-  $form = array();
-  $form['time_tracker_time_entries'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Time Tracker Time Entries'),
-    '#collapsible' => TRUE,
-    '#collapsed' => variable_get('time_entry_table_default_collapsed', 0),
-  );
-  $form['time_tracker_time_entries']['entry_table'] = array(
-    '#value' => theme('table', $header, $rows, array('class' => 'time_tracker_time_entries')),
-  );
-  return drupal_render($form);
-}
-
-/**
- * Theme function for time entries on comments.
- *
- * @param $time_entry
- *    A time entry database object.
- *    Time entry object contains properties:
- *      $obj->teid: The time entry id
- *      $obj->nid: The node id this time entry is attached to
- *      $obj->uid: The user id to whom this time entry belongs
- *      $obj->cid: If applicable, the comment id for this time entry
- *      $obj->pid: If applicable, the casetracker project id for this time entry (deprecated)
- *      $obj->activity: The time entry Activity
- *      $obj->timestamp: The unix timestamp of when this time entry was dated
- *      $obj->start: If tracking time by interval, the start time of the entry
- *      $obj->end: If tracking time by interval, the end time of the entry
- *      $obj->duration: The time entry duration in HOURS
- *      $obj->note: Any notes about the time entry (Empty for time tracked on comments)
- *      $obj->billable: Whether this is billable or not (0 => no, 1 => yes)
- *      $obj->locked: Whether this entry has been locked, requires extra permissions
- */
-function theme_time_tracker_comment($time_entry) {
-  if (is_object($time_entry)) {
-    $rows = array();
-    $time = '';
-
-    $activity = get_activity_name($time_entry->activity);
-    if ($activity) {
-      $activity = '(' . $activity . ') ';
-    }
-
-    // If there is a time start and end, it's a time entry that was logged as an interval
-    if ($time_entry->start && $time_entry->end) {
-      //Setting up the table headers
-      $header[] = array('data' => t('Duration'));
-      if (variable_get('enable_deductions_field', 0)) {
-        $header[] = array('data' => t('Deductions'));
-        $header[] = array('data' => t('Total'));
-      }
-      $header[] = array('data' => t('Activity'));
-      $header[] = array('data' => t('Start'));
-      $header[] = array('data' => t('End'));
-      if (variable_get('enable_billable_field', 0)) {
-        $header[] = array('data' => t('Billable'));
-      }
-      if (variable_get('enable_billed_field', 0)) {
-        $header[] = array('data' => t('Billed'));
-      }
-
-      $row = array(//row
-        'data' => array( //row data
-          array( //Cell3
-            'data' => format_hours_to_hours_and_minutes($time_entry->duration),
-            'class' => 'time_entry_duration',
-          ),
-        ),
-        'class' => '', //row class
-      );//endrow
-      if (variable_get('enable_deductions_field', 0)) {
-        $row['data'][] = array(
-   	      'data' => format_hours_to_hours_and_minutes($time_entry->deductions),
-   	      'class' => 'time_entry_deductions',
-   	    );
-   	    $row['data'][] = array(
-   	      'data' => format_hours_to_hours_and_minutes($time_entry->duration - $time_entry->deductions),
-   	      'class' => 'time_entry_total',
-   	    );
-      }
-      $row['data'][] = array(
-        'data' => get_activity_name($time_entry->activity),
-        'class' => 'time_entry_activity',
- 	    );
- 	    $row['data'][] = array(
-        'data' => format_date($time_entry->start, 'custom', variable_get('time_interval_date_format', 'h:i A - M d, Y')),
-        'class' => 'time_entry_start',
- 	    );
- 	    $row['data'][] = array(
-        'data' => format_date($time_entry->end, 'custom', variable_get('time_interval_date_format', 'h:i A - M d, Y')),
-        'class' => 'time_entry_end',
- 	    );
-      if (variable_get('enable_billable_field', 0)) {
-        $row['data'][] = array( //Cell6
-   	      'data' => $time_entry->billable ? t('Yes') : t('No'),
-   	      'class' => 'time_entry_billable',
-   	    );
-      }
-      if (variable_get('enable_billed_field', 0)) {
-        $row['data'][] = array( //Cell6
-   	      'data' => $time_entry->billed ? t('Yes') : t('No'),
-   	      'class' => 'time_entry_billed',
-   	    );
-      }
-      $rows[] = $row;
-      return theme('table', $header, $rows, array('class' => 'time_tracker_entry_comment'));
-    }
-    else {
-      $time_string = array();
-      $time_string['total'] = format_hours_to_hours_and_minutes($time_entry->duration - $time_entry->deductions);
-      if (variable_get('enable_deductions_field', 0)) {
-        $time_string['total_details'] = '(' . format_hours_to_hours_and_minutes($time_entry->duration) . ' - ' . format_hours_to_hours_and_minutes($time_entry->deductions) . ')';
-      }
-      $time_string['activity'] = $activity;
-      $time_string['on'] = t('on');
-      $time_string['time'] = format_date($time_entry->timestamp, 'custom', variable_get('timestamp_date_format', 'F d, Y'));
-      if (variable_get('enable_billable_field', 0)) {
-        $time_string['billable'] = $time_entry->billable ? t('Billable: Yes.') : t('Billable: No.');
-      }
-      if (variable_get('enable_billed_field', 0)) {
-        $time_string['billed'] = $time_entry->billed ? t('Billed: Yes.') : t('Billed: No.');
-      }
-
-      $rows[] = array(t('Time') . ': ' . implode(' ', $time_string));
-
-
-      return theme('table', NULL, $rows, array('class' => 'time_tracker_entry_comment'));
-    }
-  }
-}
-
-/**
- * Theme function for the time tracker entry summary.
- *
- * @param $total_time
- *    Amount of time in hours
- *
- * @return
- *    A themed table of summary data
- */
-function theme_time_tracker_summary($total_time) {
-  $rows = array();
-
-  if ($total_time > 0) {
-    $rows[] = array(t('Time logged: ') . '<span class="time_tracker_time">' .
-                    format_hours_to_hours_and_minutes($total_time, FALSE, TRUE) . '</span>');
-  }
-
-  return theme('table', NULL, $rows, array('class' => 'time_tracker_summary'));
-}
-
-/**
- * Theme function for case_tracker projects.
- *
- * NOT IN USE RIGHT NOW!
- *
- * @param $total_time
- *    Amount of time in hours
- *
- * @return
- *    A themed table of summary data
- */
-function theme_time_tracker_project_summary($total_time) {
-  // COPY OF theme_time_tracker_summary() ...
-}
-
-
-/**
- * Preprocess function that will tell the template file whether or not
- * to show the comment
- *
- * The $hide variable is already in the template file (comment.tpl.php)
- * it's just not being used right now by any other modules... so let's use it!
- */
-function time_tracker_preprocess_comment(&$vars) {
-  $comment = $vars['comment'];
-  if ($comment->status == 2 && variable_get('hide_comments', 0) && !user_access('view all time tracker entries')) {
-    $vars['hide'] = TRUE;
-  }
-}
-
-/***********************************************************************
- * API FUNCTIONS
- ***********************************************************************/
-
-/**
- * Returns all the time tracker entries for a node
- *
- * @param $nid
- *    The nid of the node to retrieve the time entries for
- *
- * @param $type
- *    Optional parameter to specify which time entries to return:
- *    'all': Returns all time entries
- *    'comment': Returns only comment based time entries
- *    'node': Returns only node based time entries
- *
- * @return
- *    Returns an array of time tracker entry objects
- */
-function time_tracker_get_time_entries_for_node($nid, $type = 'all') {
-  $time_entries = array();
-  switch ($type) {
-    case 'node':
-      $sql = "SELECT * FROM {time_tracker_entry} AS t
-              WHERE nid = %d AND cid = 0
-              ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
-      // Get the entries associated with this node
-      $resource = db_query($sql, $nid);
-      // Store the db objects in an array for theme function
-      while ($time_entry = db_fetch_object($resource)) {
-        $time_entries[] = $time_entry;
-      }
-      break;
-    case 'comment':
-      $sql = "SELECT * FROM {time_tracker_entry} AS t
-              WHERE nid = %d AND cid <> 0
-              ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
-      // Get the entries associated with this node
-      $resource = db_query($sql, $nid);
-      // Store the db objects in an array for theme function
-      while ($time_entry = db_fetch_object($resource)) {
-        $time_entries[] = $time_entry;
-      }
-      breal;
-    case 'all':
-      $sql = "SELECT * FROM {time_tracker_entry} AS t
-              WHERE nid = %d
-              ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
-      // Get the entries associated with this node
-      $resource = db_query($sql, $nid);
-      // Store the db objects in an array for theme function
-      while ($time_entry = db_fetch_object($resource)) {
-        $time_entries[] = $time_entry;
-      }
-      break;
-  }
-  return $time_entries;
-}
-
-/**
- * Returns the enabled time tracker fields
- *
- * @param $type
- *    Optional parameter to specify which time entries to return:
- *    'all': Returns all time entries
- *    'comment': Returns only comment based time entries
- *    'node': Returns only node based time entries
- *
- * @return
- *    Returns an array of time tracker entry objects
- */
-function time_tracker_get_enabled_fields($type = 'node') {
-  $enabled_fields = array();
-
-  return $enabled_fields;
-}
-
-/**
- * Returns true if either we are tracking time on the case
- * either on the comments or the node
- *
- * @param $node_type
- *    The node type to check if we are tracking time on it
- *
- * @return
- *    Returns FALSE if we're not tracking time on this node
- *    type, otherwise returns a string of either 'both' 'node'
- *    or 'comment'
- */
-function time_tracker_is_tracking_time($node_type) {
-  $tracking = FALSE;
-  if (variable_get('time_tracker_nodes_' . $node_type, 0) && variable_get('time_tracker_comments_' . $node_type, 0)) {
-    $tracking = TIME_TRACKER_BOTH;
-  }
-  elseif (variable_get('time_tracker_nodes_' . $node_type, 0)) {
-    $tracking = TIME_TRACKER_NODE;
-  }
-  elseif (variable_get('time_tracker_comments_' . $node_type, 0)) {
-    $tracking = TIME_TRACKER_COMMENT;
-  }
-  return $tracking;
-}
-
-/**
- * Returns the activity name for a givent activity id
- *
- * @param $activity_id
- *    The id of the activity
- *
- * @return
- *    The name of the activity
- */
-function get_activity_name($activity_id) {
-  $result = db_query("SELECT name FROM {time_tracker_activity} WHERE taid = '". $activity_id ."'");
-  $activity = db_fetch_object($result);
-
-  return $activity->name;
-}
-
-/**
- * Calculates the total logged time for a particular node
- *
- * @param $nid
- *    The nid of the node to calculate the total logged time
- *
- * @return
- *    Returns the total logged time ona node. Includes both
- *    comment and node based time entries
- */
-function time_tracker_get_total_logged_time($nid) {
-
-  // Initialize the $total_time variable to 0
-  $total_time = 0;
-
-  // if this is a node form display the time tracker
-  $resource = db_query("SELECT * FROM {time_tracker_entry} WHERE nid = %d", $nid);
-
-  while ($time_entry = db_fetch_object($resource)) {
-    $total_time = $total_time + ($time_entry->duration - $time_entry->deductions);
-  }
-
-  return $total_time;
-}
-
-
-/***********************************************************************
- * HELPER FUNCTIONS -- Public
- ***********************************************************************/
-
-/**
- * Formats hours (e.g. 4.5 hours) into an hours and minutes string
- *
- * @param $hours
- *    The amount of time to format in hours
- *
- * @param $clock_time
- *    Optional Parameter to format the output as clock time (hh:mm)
- *
- * @param $abbrev_hrs
- *    Optional parameter to abbreviate the text for 'hours' to 'hrs'
- *    Default is set to un-abbreviated
- *
- * @param $abbrev_mins
- *    Optional parameter to abbreviate the text for 'minutes' to 'mins'
- *    Default is set to abbreviated
- *
- * @param $sep
- *    Optional separator for the hours and minutes. Default is ', '
- *    e.g. 10 hours, 30 minutes
- *
- */
-function format_hours_to_hours_and_minutes($hours, $clock_time = FALSE, $abbrev_hrs = FALSE, $abbrev_mins = TRUE, $sep = ', ') {
-  $hrs = floor($hours);
-  $mins = round(($hours - $hrs) * 60);
-  if ($mins == 60) {
-    $mins = 0;
-    $hrs++;
-  }
-  if ($clock_time) {
-    if ($mins < 10) {
-      $mins = '0' . $mins;
-    }
-    return $hrs . ':' . $mins;
-  }
-  else {
-    // Format the 'hours' text
-    if ($abbrev_hrs == TRUE) {
-      $hours_str = format_plural($hrs, '1 hr', '@count hrs');
-    }
-    else {
-      $hours_str = format_plural($hrs, '1 hour', '@count hours');
-    }
-    // Don't show minutes if there are none
-    if ($mins == 0) {
-      return $hours_str;
-    }
-    else {
-      if ($abbrev_mins == TRUE) {
-        $minutes_str = format_plural($mins, '1 min', '@count mins');
-      }
-      else {
-        $minutes_str = format_plural($mins, '1 minute', '@count minute');
-      }
-      if ($hrs == 0) {
-        return $minutes_str;
-      }
-      else {
-        return $hours_str . ', ' . $minutes_str;
-      }
-    }
-  }
-}
-
-
-/**
- * A function to calculate the difference between a start time
- * and a stop time and return a duration in the hh:mm format
- *
- * @param $start
- *    The start time, in seconds
- *
- * @param $stop
- *    The end time, in seconds
- */
-function convert_phptime_to_duration($start, $stop = 0) {
-  if ($stop == 0) {
-    $duration = $start;
-  }
-  else {
-    $duration = $stop - $start;
-  }
-  // floor() = Always round down
-  if ($duration >= 3600) {
-    $hours = sprintf('%02d', floor($duration / 3600));
-    $mins = sprintf('%02d', floor(($duration % 3600) / 60));
-    return $hours . ":" . $mins;
-  } else {
-    $mins = sprintf('%02d', ($duration/60));
-    return '00:' . $mins;
-  }
-}
-
-/**
- * Rounds numbers to a particular time interval.
- * Can accept any single format of time (i.e. seconds, minutes, hours)
- * However, the interval format should match the value format or the
- * rounding will not work as expected.
- *
- * EXAMPLES:
- *  1) If you are passing in a UNIX timestamp which is measured in seconds
- *     and you want to round it to the neares 15 minute interval, you will
- *     need to pass in 900 as the interval (15 mins * 60 secs/min = 900)
- *  2) If you are passing in time measured in (fracional) hours (e.g. 1.5
- *     for 1 hour and 30 minutes) and you want to round it to the nearest
- *     15 minute interval, you will need to pass in 0.25 as the interval
- *     (15 mins / 60 mins/hr = 0.25)
- *
- * @param $value
- *   The value to round
- *
- * @param $interval
- *   The interval to round to. See explanation above for specifics
- *
- * @param $operation
- *   The rounding operation to use. Accepted values are:
- *    'auto': Automatically rounds up or down, which ever is closest
- *    'down': Rounds down no matter what
- *    'up': Rounds up no matter what
- *
- * @return
- *   The rounded timestamp
- */
-function time_tracker_round($value, $interval, $operation = 'auto') {
-
-  // Make sure it's a numeric value and the interval isn't 0
-  if (!is_numeric($value) || $interval <= 0) {
-    return $value;
-  }
-
-  switch ($operation) {
-    case 'auto':
-      $value = round($value / $interval) * $interval;
-      break;
-    case 'down':
-      $value = floor($value / $interval) * $interval;
-      break;
-    case 'up':
-      $value = ceil($value / $interval) * $interval;
-      break;
-  }
-
-  return $value;
-}
-
-/**
- * Helper function to get the active activities
- * Formatted as a options list array for a select form element
- */
-function get_active_activities_options() {
-  $activities = array();
-  $activities[] = '';
-  $results = db_query("SELECT * FROM {time_tracker_activity} WHERE status = 1 ORDER BY weight ASC");
-  while ($result = db_fetch_object($results)) {
-    $activities[$result->taid] = $result->name;
-  }
-  return $activities;
-}
-
-/***********************************************************************
- * HELPER FUNCTIONS -- Private
- ***********************************************************************/
-
-/**
- * Utility function that parses a duration string and converts it to fractional
- * hours.
- *
- * Durations can be specified as:
- *  * fractions: 1.25 = 1 hour, 15 minutes, or
- *  * clock times: 1:15 = 1 hour, 15 minutes
- *
- * @param string $input
- *   The user-entered duration value.
- * @return mixed
- *  Returns a time fraction, or FALSE if it could not parse the input.
- */
-function _time_tracker_parse_duration($input) {
-  $input = (string)$input;
-
-  if (!strlen($input)) {
-    return 0;
-  } elseif (preg_match('/^(\d+)?:(\d+)$/', $input, $matches)) {
-    list(, $hours, $minutes) = $matches;
-    $hours += $minutes / 60;
-  } elseif (preg_match('/^\d+(?:\.\d+)?$/', $input, $matches)) {
-    $hours = $matches[0];
-  } else {
-    return FALSE;
-  }
-
-  return $hours;
-}
-
-
+<?php
+
+/**
+ * @file
+ * Implements the basic functionality required to create and display an entity.
+ *
+ */
+
+/*
+ * Define some constants
+ */
+// Default Date formats
+define('TIME_TRACKER_DEFAULT_DATE_FORMAT', 'Y-m-d H:i');
+define('TIME_TRACKER_DEFAULT_TIMESTAMP_FORMAT', 'F d, Y');
+define('TIME_TRACKER_DEFAULT_INTERVAL_FORMAT', 'h:i A - M d, Y');
+// Constants for what we are tracking time on
+define('TIME_TRACKER_BOTH', 'both');
+define('TIME_TRACKER_NODE', 'node');
+define('TIME_TRACKER_COMMENT', 'comment');
+
+/**
+ * Implements hook_permission().
+ */
+function time_tracker_permission() {
+  return array(
+    'administer time tracker' => array(
+      'title' => t('Administer Time Tracker'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+    'add time tracker entries' => array(
+      'title' => t('Add Time Tracker Entries'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+    'view all time tracker entries' => array(
+      'title' => t('View All Time Tracker Entries'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+    'view own time tracker entries' => array(
+      'title' => t('View Own Time Tracker Entries'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+    'edit time tracker entries' => array(
+      'title' => t('Edit Time Tracker Entries'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+    'delete time tracker entries' => array(
+      'title' => t('Delete Time Tracker Entries'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+    'administer time entries' => array(
+      'title' => t('Administer Time Tracker Entries'),
+      'description' => t('TODO: Add descriptions'),
+    ),
+  );
+}
+/**
+ * Implements hook_help().
+ */
+function time_tracker_help($path, $arg) {
+  switch ($path) {
+    case 'admin/help#time_tracker':
+      // TODO: Remove html from t().
+      return t("<h2>Time Tracker</h2>
+        <p>To begin tracking time go to the edit content type screen for any content type (admin/content/node-type/%content-type-name) and scroll to the 'Time Tracker Settings' fieldset. There, you can choose to track time either on this content type's nodes or this content type's comments. Tracking time on nodes will give you a time entry sheet and a table of time entries at the bottom of a node's content, but before the comments. Tracking time on comments will add a time entry sheet to the comment form. Keep in mind that if you choose to track time on a content type's nodes as well as comments, you will only ever see comment time entries in the comment thread, and node time entries in the time entry table. However, if you were to use views to view the time entries, you could see them all with no distinction.</p>
+        <p>We recommend deciding ahead of time whether or not you would like to track time on comments or nodes. We've found that people who just want to jot down time entries with minimal notes prefer to track time on nodes. However
+        people who like extensive notes along with their time entires, as well as the ability to thread conversations based on time entries, prefer to use comments as their vessel for tracking time.</p>
+        <p>Settings for Time Tracker can be found at admin/settings/time_tracker. They should be mostly self explanatory. We recommend, however, deciding beforehand if you wish to track time using durations (e.g. 2 hours) or time intervals (e.g. 1:00pm to 2:00pm).</p>
+        <h3>Optional Fields</h3>
+        <p>Some fields are optional. They can be enabled /disabled on the time tracker settings page:</p>
+        <ul>
+        <li>Billable:   A simple checkbox to flag the time entry as billable</li>
+        <li>Billed:     A simple checkbox to flag the time entry as billed</li>
+        <li>Deductions: This field can be used to log deductions from the total time</li>
+        </ul>
+        <h3>Activities</h3>
+        <p>Activities are specific classifications for time entries. You can administer activities at admin/settings/time_tracker/activity/list.</p>
+        <p>Disabling an activity just makes it so you can't choose it anymore. Past time entries can still reference it will display the activity name.</p>
+        <p>Deleting an activity deletes it completely from the db, thus orphaning any
+        past time entries that are referencing it.</p>
+        <h3>Permissions</h3>
+        <p>Double check your permissions before getting started:</p>
+        <ul>
+        <li><em>add time tracker entries</em><br/>
+        	  Permission to allow users to track time</li>
+        <li><em>view all time tracker entries, view own time tracker entries</em><br/>
+            Allow users to view time entries</li>
+        <li><em>edit time entries</em>	<br/>
+        	  Allow users to edit time entries</li>
+        <li><em>delete time entries</em>	<br/>
+        	  Allow users to delete time entries</li>
+        <li><em>administer time tracker</em><br/>
+        	Access the administration pages</li>
+        <li><em>administer time entries</em>	<br/>
+        	  Gives access to additional options when editing a time entry:
+        	  <ul>
+        	    <li>Allows locking of time entires (if that particular setting is on)</li>
+        	    <li>Allows editing of locked time entries</li>
+        	    <li>Allows changing of username associated with a time entry</li>
+        	 </ul>
+        </li>
+        </ul>
+        ");
+      break;
+  }
+}
+/**
+ * Implements hook_menu().
+ */
+function time_tracker_menu() {
+$items = array();
+
+  $items['admin/config/people/time_tracker'] = array(
+    'title' => 'Time Tracker',
+    'description' => 'Adjust time tracker settings.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('time_tracker_settings_form'),
+    'access arguments' => array('administer time tracker'),
+    'file' => 'time_tracker.admin.inc',
+  );
+  $items['admin/config/people/time_tracker/settings'] = array(
+    'title' => 'Time Tracker',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -10,
+  );
+  $items['admin/config/people/time_tracker/activity/list'] = array(
+    'title' => 'Activities',
+    'description' => 'Adjust time tracker settings.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('time_tracker_activity_table_form'),
+    'access arguments' => array('administer time tracker'),
+    'type' => MENU_LOCAL_TASK,
+    'parent' => 'admin/config/people/time_tracker',
+    'file' => 'time_tracker.admin.inc',
+  );
+  $items['admin/config/people/time_tracker/activity/delete/%'] = array(
+    'title' => 'Delete Activity',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('time_tracker_delete_activity_confirm', 6),
+    'access arguments' => array('administer time tracker'),
+    'file' => 'time_tracker.admin.inc',
+  );
+  $items['time_entry/edit/%'] = array(
+    'title' => 'Time Entry',
+    'description' => 'Edit a Time Entry',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('time_tracker_time_entry_form', 1, 2),
+    'access arguments' => array('edit time tracker entries'),
+  );
+  $items['time_entry/add/%node'] = array(
+    'title' => 'Time Entry',
+    'description' => 'Add a Time Entry',
+    'page callback' => 'time_tracker_add_block',
+    'page arguments' => array(2),
+    'access arguments' => array('add time tracker entries'),
+  );
+
+  return $items;
+}
+
+/**
+ * Implements hook_views_api().
+ */
+function time_tracker_views_api() {
+  return array(
+    'api' => 3,
+    'path' => drupal_get_path('module', 'time_tracker') . '/views',
+  );
+}
+
+/**
+ * Implements hook_entity_info().
+ */
+function time_tracker_entity_info() {
+  $info['time_tracker_entry'] = array(
+    // A human readable label to identify our entity.
+    'label' => t('Time Entry'),
+
+    // The controller for our Entity, extending the Drupal core controller.
+    'controller class' => 'TimeTrackerController',
+
+    // The table for this entity defined in hook_schema()
+    'base table' => 'time_tracker_entry',
+
+    // Returns the uri elements of an entity
+    'uri callback' => 'time_tracker_entry_uri',
+
+    // IF fieldable == FALSE, we can't attach fields.
+    'fieldable' => TRUE,
+
+    // entity_keys tells the controller what database fields are used for key
+    // functions. It is not required if we don't have bundles or revisions.
+    // Here we do not support a revision, so that entity key is omitted.
+    'entity keys' => array(
+      'id' => 'teid' , // The 'id' (basic_id here) is the unique id.
+      'bundle' => 'bundle_type' // Bundle will be determined by the 'bundle_type' field
+    ),
+    'bundle keys' => array(
+      'bundle' => 'bundle_type',
+    ),
+
+    // FALSE disables caching. Caching functionality is handled by Drupal core.
+    'static cache' => TRUE,
+    'bundles' => array(
+      'time_entry' => array(
+        'label' => 'Time Entry',
+        // 'admin' key is used by the Field UI to provide field and
+        // display UI pages.
+        'admin' => array(
+          'path' => 'admin/config/people/time_tracker',
+          'access arguments' => array('administer time tracker'),
+        ),
+      ),
+    ),
+  );
+
+  return $info;
+}
+
+/**
+ * Implements hook_field_extra_fields().
+ */
+function time_tracker_field_extra_fields() {
+  $form_elements['time_entry_form'] = array(
+    'label' => t('Time Entry Form'),
+    'description' => t('The base time entry form'),
+    'weight' => -5,
+  );
+
+  // Since we have only one bundle type, we'll just provide the extra_fields
+  // for it here.
+  $extra_fields['time_tracker_entry']['time_entry']['form'] = $form_elements;
+
+  return $extra_fields;
+}
+
+/**
+ * Fetch a basic object.
+ *
+ * This function ends up being a shim between the menu system and
+ * time_tracker_entry_load_multiple().
+ *
+ * This function gets its name from the menu system's wildcard
+ * naming conventions. For example, /path/%wildcard would end
+ * up calling wildcard_load(%wildcard value). In our case defining
+ * the path: examples/entity_example/basic/%time_tracker_entry in
+ * hook_menu() tells Drupal to call time_tracker_entry_load().
+ *
+ * @param $teid
+ *   Integer specifying the time entry entity id.
+ * @param $reset
+ *   A boolean indicating that the internal cache should be reset.
+ * @return
+ *   A fully-loaded $basic object or FALSE if it cannot be loaded.
+ *
+ * @see time_tracker_entry_load_multiple()
+ * @see entity_example_menu()
+ */
+function time_tracker_time_entry_load($teid = NULL, $reset = FALSE) {
+  $teids = (isset($teid) ? array($teid) : array());
+  $basic = time_tracker_entry_load_multiple($teids, $reset);
+  return $basic ? reset($basic) : FALSE;
+}
+
+/**
+ * Loads multiple basic entities.
+ *
+ * We only need to pass this request along to entity_load(), which
+ * will in turn call the load() method of our entity controller class.
+ */
+function time_tracker_time_entry_load_multiple($teids = FALSE, $conditions = array(), $reset = FALSE) {
+  return entity_load('time_tracker_entry', $teids, $conditions, $reset);
+}
+
+/**
+ * Implements the uri callback.
+ */
+function time_tracker_entry_uri($basic) {
+  return array(
+    'path' => 'examples/entity_example/basic/' . $basic->basic_id,
+  );
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * Adds the options for tracking time to the
+ */
+function time_tracker_form_node_type_form_alter(&$form, &$form_state, $form_id) {
+  // what are we tracking time on?
+  if (isset($form['type'])) {
+    $form['time_tracker'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Time Tracker settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#group' => 'additional_settings',
+    );
+    $form['time_tracker']['time_tracker_nodes'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Track time on this content types nodes'),
+      '#default_value' => variable_get('time_tracker_nodes_' . $form['#node_type']->type, 0),
+      '#description' => t('Track time on this content types nodes.'),
+    );
+    $form['time_tracker']['time_tracker_comments'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Track time on this content types comments'),
+      '#default_value' => variable_get('time_tracker_comments_' . $form['#node_type']->type, 0),
+      '#description' => t('Track time on this content types comments.'),
+    );
+  }
+}
+
+/**
+ * Implements hook_node_view().
+ */
+function time_tracker_node_view($node, $view_mode, $langcode) {
+  if ($view_mode == 'full') {
+    if (user_access('view time tracker entries')) {
+      // if this is a node form display the time tracker
+      $resource = db_query("SELECT * FROM {time_tracker_entry} WHERE nid = :nid", array(':nid' => $node->nid));
+      $total_time = 0;
+      while ($time_entry = $resource->fetchObject()) {
+        $total_time = $total_time + $time_entry->duration;
+      }
+
+      $node->content['time_tracker'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Time Tracker'),
+        '#collapsible' => TRUE,
+        '#collapsed' => variable_get('time_tracker_default_collapsed', 0),
+        '#weight' => 50,
+      );
+
+      if ($total_time > 0) {
+
+        $node->content['time_tracker']['time_tracker_summary'] = array(
+          '#markup' => theme('time_tracker_summary', $total_time),
+          //'#weight' => -5,
+        );
+      }
+
+      // display the time tracking form for nodes here.
+      if (variable_get('time_tracker_nodes_' . $node->type, 0)) {
+        // Store time entries from nodes
+        $node_time_entries = array();
+        $sql = "SELECT * FROM {time_tracker_entry} AS t
+                WHERE nid = :nid AND cid = 0
+                ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
+        // Get the entries associated with this node
+        $resource = db_query($sql, array(':nid' => $node->nid));
+        // Store the db objects in an array for theme function
+        while ($time_entry = $resource->fetchObject()) {
+          $node_time_entries[] = $time_entry;
+        }
+        $node->content['time_tracker']['entries'] = array(
+          '#markup' => theme('time_tracker_time_entry_table', $node_time_entries),
+         // '#weight' => 50,
+        );
+        $entity = entity_get_controller('time_tracker_entry')->create();
+        $node->content['time_tracker']['entry_form'] = drupal_get_form('time_tracker_time_entry_form', 'node', $node->nid, $entity);
+      }
+    }
+  }
+}
+/**
+ * Implements hook_node_delete().
+ */
+function time_tracker_node_delete($node) {
+  db_delete('time_tracker_entry')
+    ->condition('nid', $node->nid)
+    ->execute();
+  db_delete('time_tracker_timer')
+    ->condition('nid', $node->nid)
+    ->execute();
+}
+
+/**
+ * Form function to create an time_tracker_entry entity.
+ *
+ * The pattern is:
+ * - Set up the form for the data that is specific to your
+ *   entity: the columns of your base table.
+ * - Call on the Field API to pull in the form elements
+ *   for fields attached to the entity.
+ */
+function time_tracker_time_entry_form($form, $form_state, $type = 'node', $id = 0, $entity) {
+   // Current user
+  global $user;
+
+  // Our base css for the form to put form elements side by side
+  drupal_add_css(drupal_get_path('module', 'time_tracker') . '/css/time_tracker.css');
+
+  // Our list of possible activities formatted as an option list for the select drop down
+  $activities = _time_tracker_get_active_activities_options();
+
+  // Assume it isn't locked for now.
+  $lock = FALSE;
+
+  // set up the entity
+  $form['time_tracker']['time_tracker_entry'] = array(
+    '#type' => 'value',
+    '#value' => $entity,
+  );
+
+  field_attach_form('time_tracker_entry', $entity, $form, $form_state);
+
+  // Display a message about the rounding if it's on and messages are set to display
+  if (variable_get('time_tracker_rounding_message', 0) && variable_get('time_tracker_rounding_interval', 0)) {
+    $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
+    $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
+    if ($rounding_operation == 'auto') {
+      $rounding_operation = 'rounded';
+    }
+    else {
+      $rounding_operation = 'rounded ' . $rounding_operation;
+    }
+    $msg = t('Time rounding is ON. Time will be !rounded to the nearest !minutes minute interval.', array('!rounded' => $rounding_operation, '!minutes' => $rounding_interval));
+    // Add it to the time_tracker fieldset
+    $form['time_tracker']['#description'] = $msg;
+  }
+
+  // If we are editing a comment...
+  if ($type == 'comment' && $id) {
+    // Gotta grab the comment's info if we're editing an old comment
+    $results = db_query("SELECT * FROM {time_tracker_entry} WHERE cid = :cid", array(':cid' => $id));
+    $time_tracker_data = $results->fetchObject();
+    // Need a comment id for comment tracking
+    $form['cid'] = array(
+      '#type' => 'value',
+      '#value' => $time_tracker_data->cid ? $time_tracker_data->cid : $id,
+    );
+  }
+  elseif ($type == 'edit' && $id) {
+    $results = db_query("SELECT * FROM {time_tracker_entry} WHERE teid = :teid", array(':teid' => $id));
+    $time_tracker_data = $results->fetchObject();
+    // The node this time entry belongs to
+    $form['nid'] = array(
+      '#type' => 'value',
+      '#value' => $time_tracker_data->nid,
+    );
+    if (user_access('delete time tracker entries') || user_access('administer time entries')) {
+      // A delete button
+      $form['time_tracker']['delete'] = array(
+        '#type' => 'submit',
+        '#value' => t('Delete'),
+        '#weight' => 9,
+        '#submit' => array('time_tracker_time_entry_delete'),
+      );
+    }
+    // We will redirect to the node this time entry belongs to once edited
+    $form['#redirect']['redirect'] = 'node/' . $time_tracker_data->nid;
+  }
+  elseif ($type == 'node' && $id) {
+    $results = db_query("SELECT * FROM {time_tracker_entry} WHERE nid = :nid", array(':nid' => $id));
+    $time_tracker_data = $results->fetchObject();
+
+    // Just need the nid for node time entries
+    $form['nid'] = array(
+      '#type' => 'value',
+      '#value' => $id,
+    );
+  }
+
+  // If there is a time tracker entry data object
+  if (isset($time_tracker_data)) {
+    // If it's an existing time entry, we need the teid
+    $form['teid'] = array(
+      '#type' => 'value',
+      //'#value' => $time_tracker_data->teid,
+    );
+    if (variable_get('allow_locked_time_entries', 0)) {
+      if (user_access('administer time entries')) {
+        $form['time_tracker']['locked'] = array(
+          '#title' => t('Locked'),
+          '#type' => 'checkbox',
+          '#description' => 'Lock this time entry, preventing further editing',
+          //'#default_value' => $time_tracker_data->locked ? TRUE : FALSE,
+          '#weight' => 6,
+        );
+      }
+      elseif ($time_tracker_data->locked) {
+        // We will use $lock throughout the form to determine whether or not
+        // we should be hiding the form elements. We want to keep them intact,
+        // however for the comments form by making their type 'value' because
+        // we don't want to prevent the saving of comment forms directly, we
+        // just want to prevent the changing of time entry data.
+        $lock = TRUE;
+        $msg = 'This time entry is locked from editing.';
+        $form['time_tracker']['locked_msg'] = array(
+          '#value' => $msg,
+        );
+        unset($form['time_tracker']['delete']);
+      }
+    }
+  }
+  //if (isset($time_tracker_data)) {
+  //  $user_submit = user_load($time_tracker_data->uid);
+  //}
+  // Auto complete/select user reference but only if you have permission
+  $form['time_tracker']['username'] = array(
+    '#title' => t('User'),
+    '#access' => user_access('administer time entries'),
+    '#type' => $lock ? 'value' : variable_get('time_tracker_user_field_type', 'textfield'),
+    '#weight' => 0,
+    //'#default_value' => $user_submit->name ? $user_submit->name : $user->name,
+  );
+
+  if (variable_get('time_tracker_user_field_type', 'textfield') == 'select') {
+    $users = db_query("SELECT uid, name FROM {users} WHERE uid > 0");
+
+    while ($user_info = db_fetch_array($users)) {
+      $options[$user_info['uid']] = $user_info['name'];
+    }
+
+    //}
+    array_shift($options);
+    $form['time_tracker']['username'] += array('#options' => $options);
+    $form['time_tracker']['username']['#weight'] -= 1;
+  }
+  else {
+    $form['time_tracker']['username'] += array(
+      '#autocomplete_path' => 'user/autocomplete',
+      '#size' => '15',
+    );
+  }
+
+  // The activity choser
+  $form['time_tracker']['activity'] = array(
+    '#title' => t('Activity'),
+    '#type' => $lock ? 'value' : 'select',
+    '#weight' => 0,
+    '#options' => $activities,
+    '#required' => TRUE,
+    //'#default_value' => $time_tracker_data->activity,
+  );
+
+  // Add some javascript and css for the datepicker
+  drupal_add_library('system', 'ui.datepicker');
+  drupal_add_js(drupal_get_path('module', 'time_tracker') . '/js/datepicker.settings.js');
+
+  // Insert different form elements depending on the time_entry_method
+  if (variable_get('time_entry_method', 'duration') == 'duration') {
+    $format = variable_get('timestamp_date_format', 'F d, Y');
+    $form['time_tracker']['time_entry']['time'] = array(
+      '#title' => t('Date'),
+      '#type' => $lock ? 'value' : 'date_popup',
+      '#date_format' => $format,
+      '#date_label_position' => 'within',
+      '#size' => 20,
+      '#weight' => 0,
+      '#required' => TRUE,
+      //'#default_value' => empty($time_tracker_data->timestamp) ? date(TIME_TRACKER_DEFAULT_DATE_FORMAT, time()) : date(TIME_TRACKER_DEFAULT_DATE_FORMAT, $time_tracker_data->timestamp),
+    );
+    $form['time_tracker']['time_entry']['duration'] = array(
+      '#title' => t('Hours'),
+      '#type' => $lock ? 'value' : 'textfield',
+      '#size' => '10',
+      '#weight' => 1,
+      '#required' => TRUE,
+      //'#default_value' => $time_tracker_data->duration ? _time_tracker_format_hours_to_hours_and_minutes($time_tracker_data->duration, TRUE) : $time_tracker_data->duration,
+      '#description' => t('eg. 2.5 or 2:30 for two and a half hours'),
+    );
+  }
+  else { // Time entry method is 'interval'
+    $format = variable_get('time_interval_date_format', 'h:i A - M d, Y');
+    $form['time_tracker']['time_entry']['prefix'] = array(
+      '#value' => '<div class="time_entry">',
+      '#weight' => 0,
+    );
+    $form['time_tracker']['time_entry']['start'] = array(
+      '#title' => t('Start'),
+      '#type' => $lock ? 'value' : 'date_popup',
+     // '#default_value' => $time_tracker_data->start ? date(TIME_TRACKER_DEFAULT_DATE_FORMAT, $time_tracker_data->start) : '',
+      '#date_format' => $format,
+      '#date_label_position' => 'within',
+      '#weight' => 1,
+      '#required' => TRUE,
+    );
+    $form['time_tracker']['time_entry']['end'] = array(
+      '#title' => t('End'),
+      '#type' => $lock ? 'value' : 'date_popup',
+     // '#default_value' => $time_tracker_data->end ? date(TIME_TRACKER_DEFAULT_DATE_FORMAT, $time_tracker_data->end) : '',
+      '#date_format' => $format,
+      '#date_label_position' => 'within',
+      '#weight' => 2,
+      '#required' => TRUE,
+    );
+    $form['time_tracker']['time_entry']['suffix'] = array(
+      '#value' => '</div>',
+      '#weight' => 3,
+    );
+    // If duration data exists already we post a note to the user
+    if (isset($time_tracker_data)) {
+      if ($time_tracker_data->duration && !($time_tracker_data->end) && !($time_tracker_data->start)) {
+        $form['time_tracker']['duration_msg'] = array(
+          '#prefix' => '<div class="description"><em>',
+          '#value' => t("A duration value exists for this time entry, but no Start and End time. <br/> Saving this entry with a Start and End time will overwrite the duration<br/> Logged Duration: <b>!duration</b>", array('!duration' => _time_tracker_format_hours_to_hours_and_minutes($time_tracker_data->duration))),
+          '#suffix' => '</em></div>',
+          '#weight' => 4,
+        );
+      }
+    }
+  }
+
+  // Deductions
+  if (variable_get('enable_deductions_field', 0)) {
+    $form['time_tracker']['time_entry']['deductions'] = array(
+      '#title' => t('Deductions'),
+      '#type' => $lock ? 'value' : 'textfield',
+      '#size' => '10',
+      '#weight' => 3,
+      //'#default_value' => $time_tracker_data->deductions ? _time_tracker_format_hours_to_hours_and_minutes($time_tracker_data->deductions, TRUE) : $time_tracker_data->deductions,
+      '#description' => t('eg. 2.5 or 2:30 for two and a half hours'),
+    );
+  }
+
+  // Billable and Billed fields
+  if (variable_get('enable_billable_field', 0)) {
+    $form['time_tracker']['billable'] = array(
+      '#title' => t('Billable'),
+      '#type' => $lock ? 'value' : 'checkbox',
+      '#size' => '10',
+      '#weight' => 6,
+      //'#default_value' => $time_tracker_data->billable,
+    );
+  }
+  if (variable_get('enable_billed_field', 0)) {
+    $form['time_tracker']['billed'] = array(
+      '#title' => t('Billed'),
+      '#type' => $lock ? 'value' : 'checkbox',
+      '#size' => '10',
+      '#weight' => 6,
+      //'#default_value' => $time_tracker_data->billed,
+    );
+  }
+
+  // If this isn't meant to track time on a comment, we need a submit button and notes field
+  if ($type != 'comment') {
+    $form['time_tracker']['note'] = array(
+      '#title' => t('Note'),
+      '#type' => $lock ? 'value' : 'textarea',
+      '#weight' => 7,
+      '#rows' => 2,
+      '#resizable' => FALSE,
+      //'#default_value' => $time_tracker_data->note,
+    );
+    if (!$lock) {
+      $form['time_tracker']['submit'] = array(
+        '#type' => 'submit',
+        '#value' => t('Save'),
+        '#weight' => 8,
+      );
+    }
+  }
+    $form['#validate'][] = array('time_tracker_time_entry_form_validate');
+    $form['#submit'][] = array('time_tracker_time_entry_form_submit');
+
+  return $form;
+}
+
+
+/**
+ * Validation handler for time_tracker_entry_add_form form.
+ * We pass things straight through to the Field API to handle validation
+ * of the attached fields.
+ */
+function time_tracker_time_entry_form_validate($form, &$form_state) {
+
+  field_attach_form_validate('time_tracker_entry', $form_state['values']['time_tracker_entry'], $form, $form_state);
+  $values = $form_state['values'];
+  // Check First if we are tracking by duration or time interval
+  if (variable_get('time_entry_method', 'duration') == 'duration') {
+    // If a duration is set, but no date
+    if (strlen($values['duration']) && !strlen($values['time'])) {
+      form_set_error('time', t('Invalid Date Value. You must also set a date if you wish to log time'));
+    }
+    // If a duration is set, but it is invalid
+    if (strlen($values['duration']) && _time_tracker_parse_duration($values['duration']) === FALSE) {
+      form_set_error('duration', t('Invalid duration value. You may enter time fractions such as 1.25 or hour and minute values such as 2:30.'));
+    }
+  }
+  elseif (variable_get('time_entry_method', 'duration') == 'interval') {
+    // If there is no start time, but there is an end time
+    if (!strlen($values['start']) && strlen($values['end'])) {
+      form_set_error('start][date', t('Enter an End time, or no time at all'));
+    }
+    // If there is no end time, but there is an start time
+    if (!strlen($values['end']) && strlen($values['start'])) {
+      form_set_error('end][date', t('Enter a Start time, or no time at all'));
+    }
+      // Make sure From date is before To Date
+    if (strlen($values['start']) && strlen($values['end'])) {
+      $start = strtotime($values['start']);
+      $end = strtotime($values['end']);
+      if ($start >= $end) {
+        form_set_error('start][date', t('Invalid interval value. Start time must come before End time'));
+      }
+    }
+  }
+  elseif (isset($values['deductions'])) {
+    // If a duration is set, but it is invalid
+    if (strlen($values['deductions']) && _time_tracker_parse_duration($values['deductions']) === FALSE) {
+      form_set_error('duration', t('Invalid deductions value. You may enter time fractions such as 1.25 or hour and minute values such as 2:30.'));
+    }
+  }
+
+}
+
+
+/**
+ * Form submit handler: submits basic_add_form information
+ */
+function time_tracker_time_entry_form_submit($form, &$form_state) {
+  // Our array for drupal_write_record
+  $time = array();
+  // Our submitted form values
+  $values = $form_state['values'];
+  $entity = $form_state['values']['time_tracker_entry'];
+  field_attach_submit('time_tracker_entry', $entity, $form, $form_state);
+  // Need a user
+  $user = user_load_by_name($values['username']);
+
+  // Store the rounding data
+  $rounding_interval = variable_get('time_tracker_rounding_interval', 0);
+  $rounding_operation = variable_get('time_tracker_rounding_operation', 'auto');
+
+  // Special handling based on the time entry method
+  if (variable_get('time_entry_method', 'duration') == 'duration') {
+    $entity->start = 0;
+    $entity->end = 0;
+    $entity->duration = _time_tracker_round(_time_tracker_parse_duration($values['duration']), $rounding_interval / 60, $rounding_operation);
+    $entity->timestamp = strtotime($values['time']);
+  }
+  elseif (variable_get('time_entry_method', 'duration') == 'interval') {
+    $entity->start = _time_tracker_round(strtotime($values['start']), $rounding_interval * 60, $rounding_operation);
+    $$entity->end = _time_tracker_round(strtotime($values['end']), $rounding_interval * 60, $rounding_operation);
+    $entity->timestamp = $time['start'];
+    $entity->duration = _time_tracker_parse_duration(_time_tracker_convert_phptime_to_duration($time['start'], $time['end']));
+  }
+
+  // The rest of the time entry
+  $entity->activity = $values['activity'];
+  $entity->uid = $user->uid;
+  $entity->nid = $values['nid'];
+  // For comments, notes are not displayed. So we need to check if it exists.
+  $entity->note = isset($values['note']) ? $values['note'] : NULL;
+  $entity->cid = isset($values['cid']) ? $values['cid'] : NULL;
+
+  // If locked was in the form use it
+  $entity->locked = isset($values['locked']) ? $values['locked'] : 0;
+  // If billable was in the form use it
+  $entity->billable = isset($values['billable']) ? $values['billable'] : NULL;
+  // If billed was in the form use it
+  $entity->billed = isset($values['billed']) ? $values['billed'] : NULL;
+  // If billed was in the form use it
+  $entity->deductions = isset($values['deductions']) ? _time_tracker_round(_time_tracker_parse_duration($values['deductions']), $rounding_interval / 60, $rounding_operation) : NULL;
+
+  $entity = time_tracker_time_entry_save($entity);
+  //$form_state['redirect'] = 'examples/entity_example/basic/' . $entity->basic_id;
+  drupal_set_message(t('Time Entry Recorded'));
+}
+
+/**
+ * Form deletion handler.
+ *
+ * @todo: 'Are you sure?' message.
+ */
+function time_tracker_entry_edit_delete( $form , &$form_state ) {
+  $entity = $form_state['values']['basic_entity'];
+  time_tracker_entry_delete($entity);
+  drupal_set_message(t('The entity %item_description (ID %id) has been deleted',
+    array('%item_description' => $entity->item_description, '%id' => $entity->basic_id))
+  );
+  $form_state['redirect'] = 'examples/entity_example';
+}
+
+/**
+ * We save the entity by calling the controller.
+ */
+function time_tracker_time_entry_save(&$entity) {
+  return entity_get_controller('time_tracker_entry')->save($entity);
+}
+
+/**
+ * Use the controller to delete the entity.
+ */
+function time_tracker_entry_delete($entity) {
+  entity_get_controller('time_tracker_entry')->delete($entity);
+}
+
+
+/***********************************************************************
+ * API FUNCTIONS
+ ***********************************************************************/
+
+/**
+ * Returns all the time tracker entries for a node
+ *
+ * @param $nid
+ *    The nid of the node to retrieve the time entries for
+ *
+ * @param $type
+ *    Optional parameter to specify which time entries to return:
+ *    'all': Returns all time entries
+ *    'comment': Returns only comment based time entries
+ *    'node': Returns only node based time entries
+ *
+ * @return
+ *    Returns an array of time tracker entry objects
+ */
+function time_tracker_get_time_entries_for_node($nid, $type = 'all') {
+  $time_entries = array();
+  switch ($type) {
+    case 'node':
+      $sql = "SELECT * FROM {time_tracker_entry} AS t
+              WHERE nid = %d AND cid = 0
+              ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
+      // Get the entries associated with this node
+      $resource = db_query($sql, $nid);
+      // Store the db objects in an array for theme function
+      while ($time_entry = $resource->fetchObject()) {
+        $time_entries[] = $time_entry;
+      }
+      break;
+    case 'comment':
+      $sql = "SELECT * FROM {time_tracker_entry} AS t
+              WHERE nid = %d AND cid <> 0
+              ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
+      // Get the entries associated with this node
+      $resource = db_query($sql, $nid);
+      // Store the db objects in an array for theme function
+      while ($time_entry = $resource->fetchObject()) {
+        $time_entries[] = $time_entry;
+      }
+      breal;
+    case 'all':
+      $sql = "SELECT * FROM {time_tracker_entry} AS t
+              WHERE nid = %d
+              ORDER BY t.timestamp DESC, t.start DESC, t.teid DESC";
+      // Get the entries associated with this node
+      $resource = db_query($sql, $nid);
+      // Store the db objects in an array for theme function
+      while ($time_entry = $resource->fetchObject()) {
+        $time_entries[] = $time_entry;
+      }
+      break;
+  }
+  return $time_entries;
+}
+
+/**
+ * Returns the enabled time tracker fields
+ *
+ * @param $type
+ *    Optional parameter to specify which time entries to return:
+ *    'all': Returns all time entries
+ *    'comment': Returns only comment based time entries
+ *    'node': Returns only node based time entries
+ *
+ * @return
+ *    Returns an array of time tracker entry objects
+ */
+function time_tracker_get_enabled_fields($type = 'node') {
+  $enabled_fields = array();
+  return $enabled_fields;
+}
+
+/**
+ * Returns true if either we are tracking time on the case
+ * either on the comments or the node
+ *
+ * @param $node_type
+ *    The node type to check if we are tracking time on it
+ *
+ * @return
+ *    Returns FALSE if we're not tracking time on this node
+ *    type, otherwise returns a string of either 'both' 'node'
+ *    or 'comment'
+ */
+function time_tracker_is_tracking_time($node_type) {
+  $tracking = FALSE;
+  if (variable_get('time_tracker_nodes_' . $node_type, 0) && variable_get('time_tracker_comments_' . $node_type, 0)) {
+    $tracking = TIME_TRACKER_BOTH;
+  }
+  elseif (variable_get('time_tracker_nodes_' . $node_type, 0)) {
+    $tracking = TIME_TRACKER_NODE;
+  }
+  elseif (variable_get('time_tracker_comments_' . $node_type, 0)) {
+    $tracking = TIME_TRACKER_COMMENT;
+  }
+  return $tracking;
+}
+
+/**
+ * Returns the activity name for a givent activity id
+ *
+ * @param $activity_id
+ *    The id of the activity
+ *
+ * @return
+ *    The name of the activity
+ */
+function _time_tracker_get_activity_name($activity_id) {
+  $result = db_query("SELECT name FROM {time_tracker_activity} WHERE taid = :taid", array(':taid' => $activity_id));
+  $activity = $result->fetchObject();
+
+  return $activity->name;
+}
+
+/**
+ * Calculates the total logged time for a particular node
+ *
+ * @param $nid
+ *    The nid of the node to calculate the total logged time
+ *
+ * @return
+ *    Returns the total logged time ona node. Includes both
+ *    comment and node based time entries
+ */
+function _time_tracker_get_total_logged_time($nid) {
+
+  // Initialize the $total_time variable to 0
+  $total_time = 0;
+
+  // if this is a node form display the time tracker
+  $resource = db_query("SELECT * FROM {time_tracker_entry} WHERE nid = :nid", array(':nid' => $nid));
+
+  while ($time_entry = $resource->fetchObject()) {
+    $total_time = $total_time + ($time_entry->duration - $time_entry->deductions);
+  }
+
+  return $total_time;
+}
+
+
+/***********************************************************************
+ * HELPER FUNCTIONS -- Public
+ ***********************************************************************/
+
+/**
+ * Formats hours (e.g. 4.5 hours) into an hours and minutes string
+ *
+ * @param $hours
+ *    The amount of time to format in hours
+ *
+ * @param $clock_time
+ *    Optional Parameter to format the output as clock time (hh:mm)
+ *
+ * @param $abbrev_hrs
+ *    Optional parameter to abbreviate the text for 'hours' to 'hrs'
+ *    Default is set to un-abbreviated
+ *
+ * @param $abbrev_mins
+ *    Optional parameter to abbreviate the text for 'minutes' to 'mins'
+ *    Default is set to abbreviated
+ *
+ * @param $sep
+ *    Optional separator for the hours and minutes. Default is ', '
+ *    e.g. 10 hours, 30 minutes
+ *
+ */
+function _time_tracker_format_hours_to_hours_and_minutes($hours, $clock_time = FALSE, $abbrev_hrs = FALSE, $abbrev_mins = TRUE, $sep = ', ') {
+  $hrs = floor($hours);
+  $mins = round(($hours - $hrs) * 60);
+  if ($mins == 60) {
+    $mins = 0;
+    $hrs++;
+  }
+  if ($clock_time) {
+    if ($mins < 10) {
+      $mins = '0' . $mins;
+    }
+    return $hrs . ':' . $mins;
+  }
+  else {
+    // Format the 'hours' text
+    if ($abbrev_hrs == TRUE) {
+      $hours_str = format_plural($hrs, '1 hr', '@count hrs');
+    }
+    else {
+      $hours_str = format_plural($hrs, '1 hour', '@count hours');
+    }
+    // Don't show minutes if there are none
+    if ($mins == 0) {
+      return $hours_str;
+    }
+    else {
+      if ($abbrev_mins == TRUE) {
+        $minutes_str = format_plural($mins, '1 min', '@count mins');
+      }
+      else {
+        $minutes_str = format_plural($mins, '1 minute', '@count minute');
+      }
+      if ($hrs == 0) {
+        return $minutes_str;
+      }
+      else {
+        return $hours_str . ', ' . $minutes_str;
+      }
+    }
+  }
+}
+
+
+/**
+ * A function to calculate the difference between a start time
+ * and a stop time and return a duration in the hh:mm format
+ *
+ * @param $start
+ *    The start time, in seconds
+ *
+ * @param $stop
+ *    The end time, in seconds
+ */
+function _time_tracker_convert_phptime_to_duration($start, $stop = 0) {
+  if ($stop == 0) {
+    $duration = $start;
+  }
+  else {
+    $duration = $stop - $start;
+  }
+  // floor() = Always round down
+  if ($duration >= 3600) {
+    $hours = sprintf('%02d', floor($duration / 3600));
+    $mins = sprintf('%02d', floor(($duration % 3600) / 60));
+    return $hours . ":" . $mins;
+  }
+  else {
+    $mins = sprintf('%02d', ($duration/60));
+    return '00:' . $mins;
+  }
+}
+
+/**
+ * Rounds numbers to a particular time interval.
+ * Can accept any single format of time (i.e. seconds, minutes, hours)
+ * However, the interval format should match the value format or the
+ * rounding will not work as expected.
+ *
+ * EXAMPLES:
+ *  1) If you are passing in a UNIX timestamp which is measured in seconds
+ *     and you want to round it to the neares 15 minute interval, you will
+ *     need to pass in 900 as the interval (15 mins * 60 secs/min = 900)
+ *  2) If you are passing in time measured in (fracional) hours (e.g. 1.5
+ *     for 1 hour and 30 minutes) and you want to round it to the nearest
+ *     15 minute interval, you will need to pass in 0.25 as the interval
+ *     (15 mins / 60 mins/hr = 0.25)
+ *
+ * @param $value
+ *   The value to round
+ *
+ * @param $interval
+ *   The interval to round to. See explanation above for specifics
+ *
+ * @param $operation
+ *   The rounding operation to use. Accepted values are:
+ *    'auto': Automatically rounds up or down, which ever is closest
+ *    'down': Rounds down no matter what
+ *    'up': Rounds up no matter what
+ *
+ * @return
+ *   The rounded timestamp
+ */
+function _time_tracker_round($value, $interval, $operation = 'auto') {
+
+  // Make sure it's a numeric value and the interval isn't 0
+  if (!is_numeric($value) || $interval <= 0) {
+    return $value;
+  }
+
+  switch ($operation) {
+    case 'auto':
+      $value = round($value / $interval) * $interval;
+      break;
+    case 'down':
+      $value = floor($value / $interval) * $interval;
+      break;
+    case 'up':
+      $value = ceil($value / $interval) * $interval;
+      break;
+  }
+
+  return $value;
+}
+
+/**
+ * Helper function to get the active activities
+ * Formatted as a options list array for a select form element
+ */
+function _time_tracker_get_active_activities_options() {
+  $activities = array();
+
+  $results = db_query("SELECT * FROM {time_tracker_activity} WHERE status = 1 ORDER BY weight ASC");
+  while ($result = $results->fetchObject()) {
+    $activities[$result->taid] = $result->name;
+  }
+  return $activities;
+}
+
+/***********************************************************************
+ * HELPER FUNCTIONS -- Private
+ ***********************************************************************/
+
+/**
+ * Utility function that parses a duration string and converts it to fractional
+ * hours.
+ *
+ * Durations can be specified as:
+ *  * fractions: 1.25 = 1 hour, 15 minutes, or
+ *  * clock times: 1:15 = 1 hour, 15 minutes
+ *
+ * @param string $input
+ *   The user-entered duration value.
+ * @return mixed
+ *  Returns a time fraction, or FALSE if it could not parse the input.
+ */
+function _time_tracker_parse_duration($input) {
+  $input = (string)$input;
+
+  if (!strlen($input)) {
+    return 0;
+  }
+  elseif (preg_match('/^(\d+)?:(\d+)$/', $input, $matches)) {
+    list(, $hours, $minutes) = $matches;
+    $hours += $minutes / 60;
+  }
+  elseif (preg_match('/^\d+(?:\.\d+)?$/', $input, $matches)) {
+    $hours = $matches[0];
+  }
+  else {
+    return FALSE;
+  }
+
+  return $hours;
+}
+
+/**
+ * Implements hook_action_info().
+ */
+function time_tracker_action_info() {
+  return array(
+    'time_tracker_billed_action' => array(
+      'label' => t('Mark entries as billed'),
+      'type' => 'time_tracker',
+      'configurable' => FALSE,
+      'triggers' => array('time_tracker_billed'),
+    ),
+  );
+}
+
+function time_tracker_billed_action($teids, $context) {
+  foreach ($teids as $teid) {
+    db_update('time_tracker_entry')
+      ->fields(array(
+        'billed' => 1,
+      ))
+      ->condition('teid', $teid, '=')
+      ->execute();
+  }
+}
+
+/**
+ * Implements hook_theme().
+ */
+function time_tracker_theme() {
+  return array(
+    'time_tracker_time_entry_table' => array(
+      'file' => 'time_tracker.theme.inc',
+    ),
+    'time_tracker_comment' => array(
+      'variables' => array('data' => NULL),
+    ),
+    'time_tracker_project_summary' => array(), // not in use
+    'time_tracker_summary' => array(
+      'file' => 'time_tracker.theme.inc',
+    ),
+    'time_tracker_activity_table' => array(
+      'render element' => 'form',
+      'file' => 'time_tracker.theme.inc',
+    ),
+  );
+}
\ No newline at end of file
diff --git a/time_tracker_timer.info b/time_tracker_timer.info
deleted file mode 100644
index 3c063ee..0000000
--- a/time_tracker_timer.info
+++ /dev/null
@@ -1,5 +0,0 @@
-name = Time Tracker Timer
-description = Provides a timer function for the time tracker module.
-package = Time Tracker
-core = 6.x
-dependencies[] = time_tracker
\ No newline at end of file
diff --git a/time_tracker_timer.install b/time_tracker_timer.install
deleted file mode 100644
index 3f105a0..0000000
--- a/time_tracker_timer.install
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-/**
- * @file
- * Implementation of hook_install().
- */
-function time_tracker_timer_schema() {
-  $schema = array();
-
-  $schema['time_tracker_timer'] = array(
-    'fields' => array(
-      'ttid' => array(
-        'type' => 'serial',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-      'nid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'start' => array(
-        'type' => 'int',
-        'unsigned' => FALSE,
-        'default' => 0,
-      ),
-      'stop' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'total' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-      'deductions' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'default' => 0,
-      ),
-    ),
-    'primary key' => array('ttid'),
-  );
-
-  return $schema;
-}
-
-function time_tracker_timer_install() {
-  drupal_install_schema('time_tracker_timer');
-}
-
-function time_tracker_timer_uninstall() {
-  drupal_uninstall_schema('time_tracker_timer');
-}
-
-/**
- * Adds the 'total' field to the timer table
- */
-function time_tracker_timer_update_6100() {
-  $return = array();
-  db_add_field($return, 'time_tracker_timer', 'total', array('type' => 'int', 'not_null' => TRUE, 'unsigned' => TRUE));
-  return $return;
-}
-
-/**
- * Adds the 'deductions' field to the timer table
- */
-function time_tracker_timer_update_6101() {
-  $return = array();
-  db_add_field($return, 'time_tracker_timer', 'deductions', array('type' => 'int', 'not_null' => TRUE, 'unsigned' => TRUE));
-  return $return;
-}
-
-/**
- * Remove the pid field
- * Re-configure the database columns
- */
-function time_tracker_timer_update_6102() {
-  $return = array();
-  db_drop_field($return, 'time_tracker_timer', 'pid');
-  db_change_field($return, 'time_tracker_timer', 'uid', 'uid', array(
-    'type' => 'int',
-    'not null' => TRUE,
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_timer', 'start', 'start', array(
-    'type' => 'int',
-    'unsigned' => FALSE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_timer', 'stop', 'stop', array(
-    'type' => 'int',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_timer', 'total', 'total', array(
-    'type' => 'int',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  db_change_field($return, 'time_tracker_timer', 'deductions', 'deductions', array(
-    'type' => 'int',
-    'unsigned' => TRUE,
-    'default' => 0,
-  ));
-  return $return;
-}
diff --git a/time_tracker_timer.module b/time_tracker_timer.module
deleted file mode 100644
index 30a7190..0000000
--- a/time_tracker_timer.module
+++ /dev/null
@@ -1,924 +0,0 @@
-<?php
-/**
- * @file
- * Enables time tracking on comments.
- */
- 
-
-function time_tracker_timer_init() {
-  drupal_add_css(drupal_get_path('module', 'time_tracker_timer') .'/css/time_tracker_timer.css');
-}
-
-/***********************************************************************
- * DRUPAL HOOKS
- ***********************************************************************/
-
-/**
- * Implementation of hook_perm().
- */
-function time_tracker_timer_perm() {
-  return array('view all timers', 'manually enter time', 'manually enter deductions', 'administer time tracker timer');
-}
-
-/**
- * Implementation of hook_help().
- */
-function time_tracker_timer_help($section, $arg) {
-  switch ($section) {
-    case 'admin/help#time_tracker_timer':
-      return t("<h2>Time Tracker Timer</h2>
-        <p>This module adds a simple timer for tracking time. Users can start the timer before beginning work and stop the timer when finished. The time entry form fields are then automatically updated with the timer results for easy time logging.</p>
-        <p>This module also comes with an (current user's) Active Timers block as well as Page which will show all active timers throughout the site (needs permission 'view all timers')</p>
-        <h3>Resuming the timer</h3>
-        <p>The timer can also be resumed once stopped. For duration based time entries this works as expected, however in order to be able to resume the timer for interval based time entries, you must enable the deductions field. The time in which the timer is stopped is logged in the deductions field and the start and end times are the first time the timer is started, and the last time it was stopped, respectively.</p>
-        <h3>Permissions</h3>
-        <p>The time tracker timer by default disables manual time entry. Manual time entry can be re-enabled using the permission 'manually enter time'.</p>
-        <p>You can also separately enable or disable manual time entry for the deductions field using the permission 'manually enter deductions'</p>
-        ");
-      break;
-  }
-}
-
-/**
- * Implementation of hook_menu().
- *
- */
-function time_tracker_timer_menu() {
-  $items = array();
-
-  $items['time_tracker_timer/active'] = array(
-    'title' => 'Active Timers',
-    'description' => 'Currently active time tracker timers.',
-    'page callback' => 'time_tracker_timer_active_timers',
-    'access arguments' => array('view all timers'),
-    'type' => MENU_CALLBACK,
-  );
-  
-  $items['members/active_timers'] = array(
-    'title' => 'Active Timers',
-    'description' => 'Currently active time tracker timers.',
-    'page callback' => 'time_tracker_timer_active_timers',
-    'access arguments' => array('view all timers'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 10,
-  );
-
-  $items['admin/settings/time_tracker/timer'] = array(
-    'title' => 'Time Tracker Timer',
-    'description' => 'Configuration settings for the time tracker timer.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('time_tracker_timer_settings_form'),
-    'access arguments' => array('administer time tracker timer'),
-    'type' => MENU_LOCAL_TASK,
-    'parent' => 'admin/settings/time_tracker',
-  );
-
-  return $items;
-}
-
-function time_tracker_timer_settings_form() {
-    $form = array();
-
-    $form['time_tracker_timer_settings']['time_tracker_timer_allow_multiple'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Allow users to have multiple active timers at one time'),
-      '#default_value' => variable_get('time_tracker_timer_allow_multiple', FALSE),
-      '#description' => t('Allow multiple timers per user.'),
-    );
-
-    return system_settings_form($form);
-}
-
-function time_tracker_timer_settings_form_submit($form, &$form_state) {
-  foreach ($form_state['values'] as $taid => $activity) {
-    drupal_write_record('time_tracker_activity', $form[$taid]['#activity'], array('taid'));
-  }
-}
-
-/**
- * Implementation of hook_forms()
- *
- * This hook allows modules to build multiple forms from a single form 
- * "factory" function but each form will have a different form id for 
- * submission, validation, theming or alteration by other modules.
- *
- * The callback arguments will be passed as parameters to the function. 
- * Callers of drupal_get_form() are also able to pass in parameters. 
- * These will be appended after those specified by hook_forms().
- *
- * @param $form_id
- *    This is the form_id passed into drupal_get_form()
- *
- * @param $args
- *    An Array of the parameters that should be passed into the form funciton
- */
-function time_tracker_timer_forms($form_id,$args){
-  //Check if the form_id passed to drupal_get_form() contains the string 'mymodule_form'
-  if (strpos($form_id, 'time_tracker_timer_startstop_form') !== FALSE) {
-    // Lets attach mymodule_form to $forms[$form_id].  
-    // This effectively allows you to use the same form builder 
-    // function to build a form with any form_id of your choice.
-      $forms[$form_id] = array(
-        'callback' => 'time_tracker_timer_startstop_form',
-      );
-      return $forms;
-   }
-}
-
-/**
- * Implementation of hook_nodeapi().
- */
-function time_tracker_timer_nodeapi(&$node, $op) {
-  switch ($op) {
-    case 'view':
-      if (time_tracker_is_tracking_time($node->type) && user_access('add time tracker entries')) {
-        if (user_access('view all timers')) {
-          $timer_results = db_query("SELECT * FROM {time_tracker_timer} WHERE nid = %d", $node->nid);
-        } else {
-          global $user;
-          $timer_results = db_query("SELECT * FROM {time_tracker_timer} WHERE nid = %d AND uid = %d", $node->nid, $user->uid);
-        }
-        $timers = array();
-        while ($timer = db_fetch_object($timer_results)) {
-          $timers[] = $timer;
-        }
-        // Theme the timers and add them to the content of the node
-        $node->content['time_tracker_timer'] = array(
-          '#value' => theme('time_tracker_timer', $timers, $node),
-          '#prefix' => '<div class="time-tracker-timer-form-wrapper">',
-          '#suffix' => '</div>',
-          '#weight' => -4,
-        );
-      }
-    break;
-  }
-}
-
-/***********************************************************************
- * TIME TRACKER TIMER FORM
- ***********************************************************************/
-
-/**
- * Builds the form for the timer
- */
-function time_tracker_timer_startstop_form($form, $node, $timer_state, $start_time=0, $uid=0) {
-  global $user;
-  if ($uid == 0) {
-    $uid = $user->uid;
-  }
-  $form = array();
-  // We need to pass the case details here.
-  $form['nid'] = array(
-    '#type' => 'value',
-    '#value' => $node->nid,
-  );
-  
-  $form['uid'] = array(
-    '#type' => 'value',
-    '#value' => $uid,
-  );
-  
-  $form['timer_state'] = array(
-    '#type' => 'value',
-    '#value' => $timer_state,
-  );
-
-  if ($timer_state == 'new') {
-    $form['submit'] = array(
-      '#value' => t('Start timer'),
-      '#type' => 'submit',
-      '#button_type' => 'timer_control_start',
-      '#submit' => array('time_tracker_timer_startstop_form_start_submit'),
-    );
-  } 
-  elseif ($timer_state == 'active') {
-    $form['start_time'] = array(
-      '#type' => 'value',
-      '#value' => $start_time,
-    );
-    $form['stop'] = array(
-      '#type' => 'submit',
-      '#value' => t('Stop Timer'),
-      '#button_type' => 'timer_control_stop',
-      '#submit' => array('time_tracker_timer_startstop_form_stop_submit'),
-    );
-  } 
-  elseif ($timer_state == 'stopped') {
-    if (variable_get('time_entry_method', 'duration') == 'duration' || (variable_get('time_entry_method', 'duration') == 'interval' && variable_get('enable_deductions_field', 0))) {
-      $form['resume'] = array(
-        '#type' => 'submit',
-        '#value' => t('Resume'),
-        '#button_type' => 'timer_control_resume',
-        '#submit' => array('time_tracker_timer_startstop_form_resume_submit'),
-      );
-      $form['reset'] = array(
-        '#type' => 'submit',
-        '#value' => t('Reset'),
-        '#button_type' => 'timer_control_reset',
-        '#submit' => array('time_tracker_timer_startstop_form_reset_submit'),
-      );
-    }
-    else {
-      $form['reset'] = array(
-        '#type' => 'submit',
-        '#value' => t('Reset'),
-        '#button_type' => 'timer_control_reset_only',
-        '#submit' => array('time_tracker_timer_startstop_form_reset_submit'),
-      );
-    }
-  }
-
-  return $form;
-}
-
-function time_tracker_timer_startstop_form_start_submit($form, &$form_state) {
-  if(!variable_get('time_tracker_timer_allow_multiple', FALSE)) {
-    $current_timers = db_query("SELECT * FROM {time_tracker_timer} WHERE uid = %d", $form_state['values']['uid']);
-    $current_timer = db_fetch_object($current_timers);
-  }
-
-  if($current_timer) {
-    drupal_set_message(t('You already have an active timer. ') . l(t('Click here to view it.'), 'node/' . $current_timer->nid), 'error');
-  } else {
-    //Create an onject to use for durpal_write_record
-    //Object must match Schema
-    $timerObj        = new stdClass();
-    $timerObj->nid   = $form_state['values']['nid']; // may need to use clicked_button?
-    $timerObj->uid   = $form_state['values']['uid'];
-    $timerObj->start = time();
-    //Write the new record
-    $success = drupal_write_record('time_tracker_timer', $timerObj);
-    //Let the user know if the write was successful (Timer was started)
-    if ($success) {
-      drupal_set_message(t('Timer started'), 'message');
-    } else {
-      drupal_set_message(t('Could not start timer'), 'error');
-    }
-  }
-}
-
-function time_tracker_timer_startstop_form_stop_submit($form, &$form_state) {
-  // Accumulated time from past pause/resumes
-  $past_time = db_result(db_query("SELECT total FROM {time_tracker_timer} WHERE nid = %d AND uid = %d", $form_state['values']['nid'], $form_state['values']['uid']));
-  // Add up this cycle and last cycles for a total amount of time
-  $cumulative_time = $past_time + (time() - $form_state['values']['start_time']);
-  // Update the db with the new data
-  $success = db_query("UPDATE {time_tracker_timer} SET stop = %d, total = %d WHERE nid = %d AND uid = %d", time(), $cumulative_time, $form_state['values']['nid'], $form_state['values']['uid']);
-  //Let the user know if the write was successful (Timer was stopped)
-  if($success) {
-    drupal_set_message(t('Timer stopped. Accumulated time: @time', array('@time' => format_interval($cumulative_time, "1"))), 'message');
-  } else {
-    drupal_set_message(t('Could not stop timer'), 'error');
-  }
-}
-
-function time_tracker_timer_startstop_form_resume_submit($form, &$form_state) {
-  if (variable_get('time_entry_method', 'duration') == 'duration') {
-    $success = db_query("UPDATE {time_tracker_timer} SET start = %d, stop = 0 WHERE nid = %d AND uid = %d", time(), $form_state['values']['nid'], $form_state['values']['uid']);
-  }
-  else {
-    $result = db_fetch_object(db_query("SELECT stop, deductions FROM {time_tracker_timer} WHERE nid = %d AND uid = %d", $form_state['values']['nid'], $form_state['values']['uid']));
-    $deductions = time() - $result->stop + $result->deductions;
-    $success = db_query("UPDATE {time_tracker_timer} SET start = %d, stop = 0, deductions = %d WHERE nid = %d AND uid = %d", time(), $deductions, $form_state['values']['nid'], $form_state['values']['uid']);
-  }
-  //Let the user know if the write was successful (Timer was stopped)
-  if($success) {
-    drupal_set_message(t('Timer resumed.'), 'message');
-  } else {
-    drupal_set_message(t('Could not resume timer'), 'error');
-  }
-}
-
-function time_tracker_timer_startstop_form_reset_submit($form, &$form_state) {
-  $success = db_query('DELETE FROM {time_tracker_timer} WHERE nid = %d AND uid = %d', $form_state['values']['nid'], $form_state['values']['uid']);
-  if($success) {
-    drupal_set_message(t('Timer reset'), 'message');
-  } else {
-    drupal_set_message(t('Could not reset timer'), 'error');
-  }
-}
-
-/**
- * Implementation of hook_form_alter()
- * 
- * This will check if it's a comment form, and if we're tracking time on it
- * If we are, then it checks for a time_tracker_timer record for the current
- * node and user and if one exists with a start AND a stop time, the time
- * is entered in the duration field of the time_tracker section.
- *
- * Also it hides any user input fields for time entries if the permission is not
- * set to allow manual time entries
- */
-function time_tracker_timer_form_alter(&$form, $form_state, $form_id) {
-  // if this is a time tracking form...
-  // Note: The time entry form and the comment form should have the same
-  // form structure even though they have different ids because we merged them
-  if (($form_id == 'comment_form' || $form_id == 'time_tracker_time_entry_form') && user_access('add time tracker entries') && empty($form['teid'])) {
-    global $user;
-    $node = node_load($form['nid']['#value']);
-    if (time_tracker_is_tracking_time($node->type)) {
-      // Only do this for the comments or time entries that don't exist yet
-      if (!$form['cid']['#value'] || !$form['teid']['#value']) {
-        $timer_results = db_query("SELECT * FROM {time_tracker_timer} WHERE nid = %d AND uid = %d", $form['nid']['#value'], $user->uid);
-        // There SHOULD be only one timer for each person per node but we'll loop anyway for now...
-        while ($timer = db_fetch_object($timer_results)) {
-          // Only do this if the timer has a start and stop value
-          if ($timer->stop != 0 && $timer->start != 0) {
-            // Extra submit function to clear the timer on save
-            $form['#submit'][] = 'time_tracker_timer_cleartimer_submit';
-            // Setup some variables
-            // Calculate the start time based on the stop time, total so far and the deductions
-            $start_time = $timer->stop - $timer->total - $timer->deductions;
-            $stop_time = $timer->stop; // need this later if manual time entry is disabled [lazy]
-            $deductions = $timer->deductions; // need this later if manual time entry is disabled [lazy]
-            $duration = $timer->total; // need this later if manual time entry is disabled [lazy]
-            // If we're logging time by Duration...
-            if (variable_get('time_entry_method', 'duration') == 'duration') {
-              $form['time_tracker']['time_entry']['time']['#default_value'] = date('Y-m-d', $start_time);
-              $form['time_tracker']['time_entry']['duration']['#default_value'] = convert_phptime_to_duration($timer->total);
-            }
-            // If we're logging time by interval
-            else {
-              $form['time_tracker']['time_entry']['start']['#default_value'] = date('Y-m-d H:i', $start_time);
-              $form['time_tracker']['time_entry']['end']['#default_value'] = date('Y-m-d H:i', $stop_time);
-              $form['time_tracker']['time_entry']['deductions']['#default_value'] = $timer->deductions ? format_hours_to_hours_and_minutes($timer->deductions / 3600, TRUE) : $timer->deductions;
-            }
-          } 
-        } // end while
-      }
-      
-      $no_manual_entry_msg = t('Manual Time Entry is currently disabled') . '<br/>' . t('Use the timer to log time');
-      $classes = 'time_entry_disabled';
-      // If we're on an existing comment, then we need just need to hide the necessary
-      // Fields if permissions don't allow manual time entry
-      if (!user_access('manually enter time') && variable_get('time_entry_method', 'duration') == 'duration') {
-        // We need to make a copy of the field for display because
-        // Disabled fields don't pass data to the submit function
-        // $form['time_tracker']['time_entry']['duration_disabled'] = $form['time_tracker']['time_entry']['duration'];
-        // Hide the actual form fields
-        $form['time_tracker']['time_entry']['duration']['#type'] = 'hidden';
-        $form['time_tracker']['time_entry']['time']['#type'] = 'hidden';
-        $form['time_tracker']['time_entry']['deductions']['#type'] = 'hidden';
-        if ($form['time_tracker']['time_entry']['duration']['#default_value']) {
-          $format = variable_get('timestamp_date_format', 'F d, Y');
-          if (user_access('manually enter deductions')) {
-            $form['time_tracker']['time_entry']['deductions']['#type'] = 'textfield';
-            $no_manual_entry_msg = t('Date : @date<br />Duration : @duration', array(
-                            '@date' => format_date($start_time, 'custom', $format),
-                            '@duration' => format_hours_to_hours_and_minutes($duration / 3600)));
-          }
-          else {
-            $form['time_tracker']['time_entry']['deductions']['#type'] = 'hidden';
-            $no_manual_entry_msg = t('Date : @date<br />Duration : @duration<br />Deductions: @deductions', array(
-                            '@date' => format_date($start_time, 'custom', $format),
-                            '@duration' => format_hours_to_hours_and_minutes($duration / 3600),
-                            '@deductions' => format_hours_to_hours_and_minutes($deductions / 3600)));
-            $classes .= ' with_deductions';
-          }
-        }
-        $form['time_tracker']['time_entry']['time_display'] = array(
-          '#value' => $no_manual_entry_msg,
-          '#weight' => 4,
-          '#prefix' => '<div class='.$classes.'>',
-          '#suffix' => '</div>',
-        );
-      } 
-      elseif (!user_access('manually enter time') && variable_get('time_entry_method', 'duration') == 'interval') {
-        // Hide the actual fields with the times
-        $form['time_tracker']['time_entry']['start']['#type'] = 'hidden';
-        $form['time_tracker']['time_entry']['end']['#type'] = 'hidden';
-        unset($form['time_tracker']['time_entry']['prefix']);
-        unset($form['time_tracker']['time_entry']['suffix']);
-        $form['time_tracker']['time_entry']['deductions']['#type'] = 'hidden';
-        // Change the container div for themeing purposes
-        // $form['time_tracker']['time_entry']['prefix']['#value'] = '<div class="time_entry_disabled">';
-        // $form['time_tracker']['time_entry']['suffix']['#value'] = '</div>';
-        // If there's a start and end time then we just display the time
-        if ($form['time_tracker']['time_entry']['start']['#default_value'] && $form['time_tracker']['time_entry']['end']['#default_value']) {
-          $format = variable_get('time_interval_date_format', 'h:i A - M d, Y');
-          if (user_access('manually enter deductions')) {
-            $form['time_tracker']['time_entry']['deductions']['#type'] = 'textfield';
-            $no_manual_entry_msg = t('Start Time : @start<br />End Time : @end', array(
-                            '@start' => format_date($start_time, 'custom', $format),
-                            '@end' => format_date($stop_time, 'custom', $format)));
-          }
-          else {
-            $no_manual_entry_msg = t('Start Time : @start<br />End Time : @end<br />Deductions: @deductions', array(
-                            '@start' => format_date($start_time, 'custom', $format),
-                            '@end' => format_date($stop_time, 'custom', $format),
-                            '@deductions' => format_hours_to_hours_and_minutes($deductions / 3600)));
-            $classes .= ' with_deductions';
-          }
-          $form['time_tracker']['time_entry']['time_display'] = array(
-            '#value' => $no_manual_entry_msg,
-            '#weight' => 4,
-            '#prefix' => '<div class="'.$classes.'">',
-            '#suffix' => '</div>',
-          );
-        }
-        // else {
-        //   //Otherwise we tell the user to use the timer
-        //   $form['time_tracker']['time_entry']['time_display']['#value'] = $no_manual_entry_msg;
-        //   $form['time_tracker']['time_entry']['time_display']['#weight'] = 4;
-        // }
-      }
-    }
-  }
-}
-
-/**
- * Function that will clear the timer on time entry submission if it exists
- * 
- * Added by hook_form_alter (above)
- */
-function time_tracker_timer_cleartimer_submit($form, &$form_state) {
-  //$timer_results = db_query("SELECT * FROM {time_tracker_timer} WHERE nid = %d AND uid = %d", $form['nid']['#value'], $user->uid);
-  //while($timer = db_fetch_object($timer_results)){
-    global $user;
-    $success = db_query('DELETE FROM {time_tracker_timer} WHERE nid = %d AND uid = %d', $form['nid']['#value'], $user->uid);
-    if(!$success) {
-      drupal_set_message(t('Could not reset timer...'), 'error');
-    }
-  //}
-}
-
-
-/***********************************************************************
- * ACTIVE TIMERS DISPLAYS
- ***********************************************************************/
-
-/**
- * The active timers page.
- */
-function time_tracker_timer_active_timers() {
-  $resource = db_query("SELECT * FROM {time_tracker_timer}");
-  
-  $active_timers = array();
-  
-  $resource = db_query("SELECT * FROM {time_tracker_timer}");
-  while($timer = db_fetch_object($resource)) {
-    $active_timers[] = $timer;
-  }
-  return theme('time_tracker_timer_active_timers_page', $active_timers);
-}
-
-/**
- * Implementation of hook_block()
- * 
- * Displays the current users active timers in a block
- */
-function time_tracker_timer_block($op='list', $delta=0, $edit=array()) {
-  switch ($op) {
-    case 'list':
-      $blocks['your_active_timers']['info'] = t('Your Active Timers');
-      return $blocks;
-
-    case 'view':
-      switch ($delta) {
-        case 'your_active_timers':
-          if (user_access('add time tracker entries')) {
-            $active_timers = array();
-            $block['subject'] = t('Your Active Timers');
-            $resource = db_query("SELECT * FROM {time_tracker_timer}");
-            while($timer = db_fetch_object($resource)) {
-              $active_timers[] = $timer;
-            }
-            $block['content'] = theme('time_tracker_timer_active_timers_block', $active_timers);
-          }
-      }
-      return $block;
-  }
-}
-
-/***********************************************************************
- * THEME IMPLEMENTATIONS
- ***********************************************************************/
-
-/**
- * Implementation of hook_theme().
- */
-function time_tracker_timer_theme() {
-  $hooks = array();
-  
-  $hooks['time_tracker_timer'] = array(
-    'arguments' => array('timer_results' => NULL, 'node' => NULL),
-  );
-  
-  $hooks['time_tracker_timer_active_timers_page'] = array(
-    'arguments' => array('active_timers' => NULL),
-  );
-  
-  $hooks['time_tracker_timer_active_timers_block'] = array(
-    'arguments' => array('active_timers' => NULL),
-  );
-  
-  return $hooks;
-  
-}
-
-/**
- * Theme function for the timer control bar on nodes
- * That are being time tracked.
- * 
- * @param $timers
- *    The list of current active timers to be listed
- * 
- * @param $node
- *    Reference to the node these timers are on
- */
-function theme_time_tracker_timer($timers, $node) {
-  $rows =        array(); // Rows for current user timer messages
-  $user_rows =   array(); // Rows for timer messages about other user timers
-  $output =      '';
-  $start_time = 0;
-  $timer_state = 'new'; // new
-  if (variable_get('time_entry_method', 'duration') == 'interval' && !variable_get('enable_deductions_field', 0)) {
-    $no_resume = ' no_resume';
-  }
-  else {
-    $no_resume = '';
-  }
-  drupal_add_js(drupal_get_path('module', 'time_tracker'). '/js/timer.js');
-
-  // Loop through the results. Should only be ONE if user doesn't have 'view all' priveleges
-  foreach ($timers as $timer) {
-    global $user;
-    // If the timer entry user id matches the current user then we process normally
-    if ($timer->uid == $user->uid) {
-      // If the timer doesn't have a stop value, it's still running
-      if($timer->stop == 0) {
-        //Change the timer state to be in "active" state
-        $timer_state = 'active'; //active
-        // Format the rows for eventual theme_table
-        $rows[] = array(
-          'data' => array(
-            array(
-              // Note to self: I am able to ennumerate this form_id because of hook_forms() (above)
-              'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start),
-              'class' => 'active_timer_control timer_control'
-            ),
-            array(
-              'data' => _time_tracker_format_secs_to_hhmmss(time() - $timer->start + $timer->total),
-              'class' => 'active_timer_time timer_time'
-            ),
-            array(
-              'data' => t('Your timer is currently active.'),
-              'class' => 'active_timer_msg timer_msg'
-            ),
-          ),
-        );
-      } 
-      else {
-        //If the timer has a stop value, then it has been stopped
-        //BUT not saved since it still exists (should be deleted when stopped and saved)
-        // Set the timer state to 'stopped' state   
-        $timer_state = 'stopped'; //stopped
-        if (time_tracker_is_tracking_time($node->type) == 'node') {
-          $hours_field_link = 'node/' . $node->nid . '#time-tracker-time-entry-form';
-        }
-        else {
-          $hours_field_link = 'node/' . $node->nid . '#comment-form';
-        }
-        $total_time = $timer->total ? $timer->total : $timer->stop - $timer->start;
-        $rows[] = array(
-          'data' => array(
-            array(
-              'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $start_time),
-              'class' => 'stopped_timer_control timer_control' . $no_resume,
-            ),
-            array(
-              'data' => _time_tracker_format_secs_to_hhmmss($total_time),//
-              'class' => 'stopped_timer_time timer_time'
-            ),
-            array(
-              'data' => t('Your time has been entered below.  <a href="!hours_field_link">Please complete the form</a>', array('!hours_field_link' => base_path() . $hours_field_link)),
-              'class' => 'stopped_timer_msg timer_msg',
-            ),
-          ),
-        );
-      }
-    } 
-    else {
-      // If the timer entry id doesn't match the user, then we just want to add it to the
-      // page to view, but not affect the how the timer button will work (i.e. start, stop, reset)
-      // Load the user name
-      $username = user_load($timer->uid)->name;
-      if($timer->stop == 0) {
-        $timer_state = 'active'; //active
-        $user_rows[] = array(
-          'data' => array(
-            array(
-              'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start, $timer->uid),//t('BUTTON PLACEHOLDER'),
-              'class' => 'active_timer_control timer_control'
-            ),
-            array(
-              'data' =>  _time_tracker_format_secs_to_hhmmss(time() - $timer->start + $timer->total),
-              'class' => 'active_timer_time timer_time'
-            ),
-            array(
-              'data' => t('@name has an unsaved timer entry for this ticket', array('@name' => $username)),
-              'class' => 'active_timer_msg timer_msg'
-            ),
-          ),
-        );
-      } 
-      else {
-        //If the timer has a stop value, then it has been stopped
-        //BUT not saved since it still exists (should be deleted when stopped and saved)
-        $timer_state = 'stopped'; //stopped
-        $total_time = $timer->total ? $timer->total : $timer->stop - $timer->start;
-        $user_rows[] = array(
-          'data' => array(
-            array(
-              'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start, $timer->uid),//t("BUTTON PLACEHOLDER"),
-              'class' => 'stopped_timer_control timer_control' . $no_resume,
-            ),
-            array(
-              'data' => _time_tracker_format_secs_to_hhmmss($total_time),//
-              'class' => 'stopped_timer_time timer_time'
-            ),
-            array(
-              'data' => t('@name has an unsaved timer entry for this ticket', array('@name' => $username)),
-              'class' => 'stopped_timer_msg timer_msg',
-            ),
-          ),
-        );
-      }
-    }
-  }
-  // If no rows were added there are no timer entries and the 'start timer' row must be displayed
-  if (sizeof($rows) == 0) {
-    $timer_state = 'new';
-    $rows[] = array(
-      'data' => array(
-        array(
-          'data' => drupal_get_form('time_tracker_timer_startstop_form_start', $node, $timer_state),
-          'class' => 'new_timer_control timer_control'
-        ),
-        array(
-          'data' => _time_tracker_format_secs_to_hhmmss(0),//
-          'class' => 'new_timer_time timer_time'
-        ),
-        array(
-          'data' => t('Click <em>start timer</em> to begin tracking your time'),
-          'class' => 'new_timer_msg timer_msg',
-        ),
-      ),
-    );
-  }
-  
-  // add the other user rows on to the end of the control rows
-  foreach($user_rows as $row) {
-    $rows[] = $row;
-  }
-  
-  // Add the output to the end of the casetracker_case_summary
-  $output = '';
-  $output .= theme('table', NULL, $rows, array('class' => 'time_tracker_timer'));
-
-  return $output;
-}
-
-/**
- * Theme function for active time_tracker_timer timers page.
- * 
- * @param $active_timers
- *    The list of current active timers to be listed
- */
-function theme_time_tracker_timer_active_timers_page($active_timers) {
-  $rows =        array(); // Rows for current user timer messages
-  $output =      '';
-  $start_time =  0;
-  $timer_state = 'new';
-  $other_timers = FALSE;
-  drupal_add_js(drupal_get_path('module', 'time_tracker'). '/js/timer.js');
-  
-  // Loop through the results.
-  foreach ($active_timers as $timer) {
-    $node = node_load($timer->nid);
-    if (module_exists('casetracker') && casetracker_is_case($node->type)) {
-      $project = node_load($node->casetracker->pid);
-      $timer_links = t('!case-link in !project-link', array(
-        '!case-link' => l($node->title, 'node/' . $node->nid),
-        '!project-link' => l($project->title, 'node/' . $project->nid),
-      ));
-    }
-    else {
-      $timer_links = l($node->title, 'node/' . $node->nid);
-    }
-    // If the timer doesn't have a stop value, it's still running
-    if($timer->stop == 0) {
-      //Change the timer state to be in "active" state
-      $timer_state = 'active';
-      $start_time = $timer->start;
-      $timer_msg = t('!username has an active timer on !timer_links', array(
-        '!username' => theme('username', user_load($timer->uid)),
-        '!timer_links' => $timer_links,
-      ));
-      // Format the rows for eventual theme_table
-      $rows[] = array(
-        'data' => array(
-          array(
-            'data' => theme_image(drupal_get_path('module', 'time_tracker') . '/css/images/time_tracker_stopwatch_icon_grey.png', 'timer icon', 'Time Tracker Timer Icon'),
-            'class' => 'timer_page_icon',
-          ),
-          // Uncomment this part to get the timer controls in the block
-          // array(
-          //   'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start),
-          //   'class' => 'active_timer_control timer_control'
-          // ),
-          array(
-            'data' =>  _time_tracker_format_secs_to_hhmmss(time() - $timer->start + $timer->total),
-            'class' => 'active_timer_time timer_page_time'
-          ),
-          array(
-            'data' => $timer_msg,
-            'class' => 'active_timer_page_msg timer_page_msg',
-          ),
-        ),
-      );
-    } 
-    else {
-      //If the timer has a stop value, then it has been stopped
-      //BUT not saved since it still exists (should be deleted when stopped and saved)
-      // Set the timer state to 'stopped' state
-      $timer_state = 'stopped';
-      $hours_field_link = $node->path . '#edit-time-wrapper';
-      $total_time = $timer->total ? $timer->total : $timer->stop - $timer->start;
-      $timer_msg = t('!username has an active timer on !timer_links', array(
-        '!username' => theme('username', user_load($timer->uid)),
-        '!timer_links' => $timer_links,
-      ));
-      $rows[] = array(
-        'data' => array(
-          array(
-            'data' => theme_image(drupal_get_path('module', 'time_tracker') . '/css/images/time_tracker_stopwatch_icon_grey.png', 'timer icon', 'Time Tracker Timer Icon'),
-            'class' => 'timer_page_icon'
-          ),
-          // Uncomment the following to get the timer controls on the page
-          // array(
-          //   'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start),
-          //   'class' => 'stopped_timer_control timer_control'
-          // ),
-          array(
-            'data' => _time_tracker_format_secs_to_hhmmss($total_time),//
-            'class' => 'stopped_timer_time timer_page_time'
-          ),
-          array(
-            'data' => $timer_msg,
-            'class' => 'active_timer_page_msg timer_page_msg',
-          ),
-        ),
-      );
-    }
-  }
-  
-  if (empty($rows)) {
-    $output = t('You have no active timers at this time');
-  }
-  else {
-    // Add the output to the end of the casetracker_case_summary
-    $output = theme('table', NULL, $rows, array('class' => 'active_timers_page'));
-  }
-
-  return $output;
-}
-
-/**
- * Theme function for active time_tracker_timer timers block.
- * 
- * @param $active_timers
- *    The list of current active timers to be listed
- */
-function theme_time_tracker_timer_active_timers_block($active_timers) {
-  
-  global $user;
-  
-  $rows =        array(); // Rows for current user timer messages
-  $output =      '';
-  $start_time =  0;
-  $timer_state = 'new';
-  $other_timers = FALSE;
-  drupal_add_js(drupal_get_path('module', 'time_tracker'). '/js/timer.js');
-  
-  // Loop through the results. Should only be ONE if user doesn't have 'view all' priveleges
-  foreach ($active_timers as $timer) {
-    $node = node_load($timer->nid);
-    if (module_exists('casetracker') && casetracker_is_case($node->type)) {
-      $project = node_load($node->casetracker->pid);
-      $timer_links = t('!case in !project', array(
-        '!case' => l($node->title, 'node/' . $node->nid),
-        '!project' => l($project->title, 'node/' . $project->nid),
-      ));
-    }
-    else {
-      $timer_links = l($node->title, 'node/' . $node->nid);
-    }
-    // If the timer entry user id matches the current user then we process normally
-    if ($timer->uid == $user->uid) {
-      // If the timer doesn't have a stop value, it's still running
-      if($timer->stop == 0) {
-        //Change the timer state to be in "active" state
-        $timer_state = 'active';
-        $start_time = $timer->start;
-        $timer_msg = t('You have an active timer on !links', array('!links' => $timer_links));
-        // Format the rows for eventual theme_table
-        $rows[] = array(
-          'data' => array(
-            array(
-              'data' => theme_image(drupal_get_path('module', 'time_tracker') . '/css/images/time_tracker_stopwatch_icon_white.png', 'timer icon', 'Time Tracker Timer Icon'),
-              'class' => 'timer_block_icon',
-            ),
-            // Uncomment this part to get the timer controls in the block
-            // array(
-            //   'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start),
-            //   'class' => 'active_timer_control timer_control'
-            // ),
-            array(
-              'data' => _time_tracker_format_secs_to_hhmmss(time() - $timer->start + $timer->total),
-              'class' => 'active_timer_time timer_block_time'
-            ),
-          ),
-        );
-        $rows[] = array(
-          'data' => array(
-            array(
-              'data' => $timer_msg,
-              'class' => 'active_timer_block_msg timer_block_msg',
-              'colspan' => 2,
-            ),
-          ),
-        );
-      } 
-      else {
-        // If the timer has a stop value, then it has been stopped
-        // BUT not saved since it still exists (should be deleted when stopped and saved)
-        // Set the timer state to 'stopped' state
-        $timer_state = 'stopped';
-        $hours_field_link = $node->path . '#edit-time-wrapper';
-        $total_time = $timer->total ? $timer->total : $timer->stop - $timer->start;
-        $timer_msg = t('You have an unsaved timer on !links.', array('!links' => $timer_links));
-        $rows[] = array(
-          'data' => array(
-            array(
-              'data' => theme_image(drupal_get_path('module', 'time_tracker') . '/css/images/time_tracker_stopwatch_icon_white.png', 'timer icon', 'Time Tracker Timer Icon'),
-              'class' => 'timer_block_icon'
-            ),
-            // Uncomment this part to get the timer controls in the block
-            // array(
-            //   'data' => drupal_get_form('time_tracker_timer_startstop_form_' . $timer->ttid, $node, $timer_state, $timer->start),
-            //   'class' => 'stopped_timer_control timer_control'
-            // ),
-            array(
-              'data' => _time_tracker_format_secs_to_hhmmss($total_time),//
-              'class' => 'stopped_timer_time timer_block_time'
-            ),
-          ),
-        );
-        $rows[] = array(
-          'data' => array(
-            array(
-              'data' => $timer_msg,
-              'class' => 'active_timer_block_msg timer_block_msg',
-              'colspan' => 2,
-            ),
-          ),
-        );
-      }
-    }
-    else {
-      // Make note that there are timers for other users
-      $other_timers = TRUE;
-    }
-  }
-  
-  if (empty($rows)) {
-    $output = t('You have no active timers at this time.');
-  }
-  else {
-    // Add the output to the end of the casetracker_case_summary
-    $output = theme('table', NULL, $rows, array('class' => 'active_timers_block'));
-  }
-  
-  if (user_access('view all timers') && $other_timers) {
-    $output .= '<div class="see_all_timers">' . l(t('See all active timers'), 'time_tracker_timer/active') . '</div>';
-  }
-
-  return $output;
-}
-
-
-/***********************************************************************
- * HELPER FUNCTIONS
- ***********************************************************************/
-
-
-/**
- * Formats php timestamps (in seconds) into hh:mm:ss - no limit on the hours
- */
-function _time_tracker_format_secs_to_hhmmss($seconds) {
-    $hours = sprintf('%02d', floor($seconds / 3600));
-    $mins = sprintf('%02d', floor(($seconds % 3600) / 60));
-    $secs = sprintf('%02d', (($seconds % 3600) % 60));
-    return $hours . ":" . $mins . ':' . $secs;
-}
\ No newline at end of file
diff --git a/views/time_tracker.views.inc b/views/time_tracker.views.inc
index c207c6c..6256d71 100644
--- a/views/time_tracker.views.inc
+++ b/views/time_tracker.views.inc
@@ -1,576 +1,521 @@
-<?php
-
-/**
- * @file
- *   Views integration for time_tracker
- */
-
-/**
- * Implements hook_views_data().
- */
-function time_tracker_views_data() {
-  $data['time_tracker_entry']['table']['group'] = t('Time Tracker');
-  $data['time_tracker_entry']['table']['base'] = array(
-    'field' => 'teid',
-    'title' => t('Time Tracker'),
-    'help' => t('Content generated from time tracker entries.'),
-  );
-
-  $data['time_tracker_entry']['teid'] = array(
-    'title' => t('ID'),
-    'help' => t('Time Entry ID.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_numeric',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['timestamp'] = array(
-    'title' => t('Timestamp'),
-    'help' => t('Timestamp of the Entry.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'time_tracker_views_handler_filter_date',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['start'] = array(
-    'title' => t('Start Time'),
-    'help' => t('Start time of the Entry.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'time_tracker_views_handler_filter_date',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['end'] = array(
-    'title' => t('End Time'),
-    'help' => t('End time of the Entry.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'time_tracker_views_handler_filter_date',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['duration'] = array(
-    'title' => t('Duration'),
-    'help' => t('The Raw Time Entry Duration (without deductions).'),
-    'field' => array(
-      'handler' => 'time_tracker_views_handler_field_numeric',
-      'float' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['note'] = array(
-    'title' => t('Note'),
-    'help' => t('Notes for node-based time entries'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['deductions'] = array(
-    'title' => t('Deductions'),
-    'help' => t('Time Entry Deductions.'),
-    'field' => array(
-      'handler' => 'time_tracker_views_handler_field_numeric',
-      'float' => TRUE,
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  // $data['time_tracker_entry']['total_duration'] = array(
-  //   'title' => t('Total Duration'),
-  //   'help' => t('Time Entry Total Duration, minus the deductions'),
-  //   'field' => array(
-  //     'handler' => 'time_tracker_views_handler_field_total_duration',
-  //     'float' => TRUE,
-  //   ),
-  //   'sort' => array(
-  //     'handler' => 'views_handler_sort',
-  //   ),
-  //   'filter' => array(
-  //     'handler' => 'views_handler_filter_numeric',
-  //   ),
-  //   'argument' => array(
-  //     'handler' => 'views_handler_argument',
-  //   ),
-  // );
-  // This isn't being used right now so I'm de-exposing it to views
-  $data['time_tracker_entry']['billable'] = array(
-    'title' => t('Billable'),
-    'help' => t('Is the Entry Billable?'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['billed'] = array(
-    'title' => t('Billed'),
-    'help' => t('Has the Entry been billed?'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['locked'] = array(
-    'title' => t('Locked'),
-    'help' => t('Is the Entry Locked?'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument',
-    ),
-  );
-  $data['time_tracker_entry']['uid'] = array(
-    'title' => t('Author'),
-    'help' => t('Relate an entry to the user who created it.'),
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'base' => 'users',
-      'base field' => 'uid',
-      'label' => t('User'),
-    ),
-  );
-  $data['time_tracker_entry']['nid'] = array(
-    'title' => t('Node'),
-    'help' => t('Relate an entry to a comments node.'),
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'base' => 'node',
-      'base field' => 'nid',
-      'label' => t('Node'),
-    ),
-  );
-  $data['time_tracker_entry']['cid'] = array(
-    'title' => t('Comment'),
-    'help' => t('Relate an entry to a comment.'),
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'base' => 'comments',
-      'base field' => 'cid',
-      'label' => t('Comment'),
-    ),
-  );
-  $data['time_tracker_entry']['activity'] = array(
-    'title' => t('Activity'),
-    'help' => t('Relate an entry to an Activity Name.'),
-    'relationship' => array(
-      'handler' => 'views_handler_relationship',
-      'base' => 'time_tracker_activity',
-      'base field' => 'taid',
-      'label' => t('Activity'),
-    ),
-  );
-
-  $data['time_tracker_activity']['table']['join']['time_tracker_entry'] = array(
-    'left_field' => 'activity',
-    'field' => 'taid',
-  );
-  $data['time_tracker_activity']['table']['group'] = t('Time Tracker');
-
-  $data['time_tracker_activity']['name'] = array(
-    'title' => t('Activity Name'),
-    'help' => t('Activity Name.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  $data['time_estimate_entry']['table']['join']['time_tracker_entry'] = array(
-    'left_field' => 'nid',
-    'field' => 'nid',
-  );
-  $data['time_estimate_entry']['table']['group'] = t('Time Tracker');
-
-  $data['time_estimate_entry']['estimate'] = array(
-    'title' => t('Time Estimate'),
-    'help' => t('Time Estimate.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_numeric',
-    ),
-  );
-
-  // Access Time Tracker Data from the comments base table
-  $data['comments']['cid'] = array(
-    'relationship' => array(
-      'title' => t('Time Tracker'),
-      'help' => t('Access time tracker data for comments.'),
-      'handler' => 'views_handler_relationship',
-      'base' => 'time_tracker_entry',
-      'base field' => 'cid',
-      'label' => t('Time Tracker'),
-    ),
-  );
-
-  // Access Time Tracker Data from the node base table
-  $data['node']['nid'] = array(
-    'relationship' => array(
-      'title' => t('Time Tracker'),
-      'help' => t('Access time tracker data for nodes.'),
-      'handler' => 'views_handler_relationship',
-      'base' => 'time_tracker_entry',
-      'base field' => 'nid',
-      'label' => t('Time Tracker'),
-    ),
-  );
-
-  // Define a "table" called 'time_tracker_totals', which will actually be
-  // a subquery that will add up all the time tracked on the node.
-  $data['time_tracker_totals'] = array(
-    'table' => array(
-      'group' => t('Time Tracker'),
-      // Join this "table" to the Node table, so this can be used in node views,
-      // which is the whole point.
-      'join' => array(
-        'node' => array(
-          'left_field' => 'nid',
-          'field' => 'nid',
-          // Use a custom join handler, which constructs the query. This is
-          // defined below.
-          'handler' => 'time_tracker_node_join_handler',
-        ),
-      ),
-    ),
-
-    // Create a field called total_time, to add up all the time tracked on
-    // a node. Allow it to be used as a numeric Field, Filter, and Sort.
-    'total_time' => array(
-      'title' => t('Total time'),
-      'help' => t('The total time tracked on the node (minus deductions)'),
-      'field' => array(
-        'handler' => 'views_handler_field_numeric',
-        'click sortable' => TRUE,
-        'float' => TRUE,
-      ),
-      'filter' => array(
-        'handler' => 'views_handler_filter_numeric',
-      ),
-      'sort' => array(
-        'handler' => 'views_handler_sort',
-      ),
-    ),
-  );
-
-  // Define another "table" called 'time_tracker_total_duration'.
-  // This one creates a compound field "total_duration" (duration - deduction)
-  // and joins it back into the time_tracker_entry table.
-  $data['time_tracker_total_duration'] = array(
-    'table' => array(
-      'group' => t('Time Tracker'),
-      // Join this "table" to the Node table, so this can be used in node views,
-      // which is the whole point.
-      'join' => array(
-        'time_tracker_entry' => array(
-          'left_field' => 'teid',
-          'field' => 'teid',
-          // Use a custom join handler, which constructs the query. This is
-          // defined below.
-          'handler' => 'time_tracker_total_duration_join_handler',
-        ),
-      ),
-    ),
-
-    // Create a field called total_duration, which is the duration minus the
-    // deductions. This belongs to the pseudo table "time_tracker_total_duration"
-    'total_duration' => array(
-      'title' => t('Total Duration'),
-      'help' => t('Time Entry Total Duration, minus the deductions'),
-      'field' => array(
-        'handler' => 'time_tracker_views_handler_field_numeric',
-        'click sortable' => TRUE,
-        'float' => TRUE,
-      ),
-      'filter' => array(
-        'handler' => 'views_handler_filter_numeric',
-      ),
-      'sort' => array(
-        'handler' => 'views_handler_sort',
-      ),
-      'argument' => array(
-        'handler' => 'views_handler_argument',
-      ),
-    ),
-  );
-
-  return $data;
-}
-
-/**
- * Implementation of hook_views_handlers() to register all of the basic handlers
- * views uses.
- */
-function time_tracker_views_handlers() {
-  return array(
-    'info' => array(
-      'path' => drupal_get_path('module', 'time_tracker') .'/views',
-     ),
-    'handlers' => array(
-      'time_tracker_views_handler_filter_date' => array(
-        'parent' => 'views_handler_filter_numeric',
-      ),
-      'time_tracker_views_handler_field_numeric' => array(
-        'parent' => 'views_handler_field_numeric',
-      ),
-      // 'time_tracker_views_handler_field_total_duration' => array(
-      //   'parent' => 'time_tracker_views_handler_field_numeric',
-      // ),
-    ),
-  );
-}
-
-
-function time_tracker_form_views_exposed_form_alter(&$form, $form_state) {
-
-  // if ($form['form_id']['#id'] == 'edit-views-exposed-form') {
-  //   if(module_exists('jquery_ui')) {
-  //     jquery_ui_add(array('ui.datepicker'));
-  //     drupal_add_js(drupal_get_path('module', 'time_tracker') .'/js/datepicker.settings.js');
-  //     drupal_add_css(drupal_get_path('module', 'jquery_ui') .'/jquery.ui/themes/default/ui.datepicker.css');
-  //     drupal_add_css(drupal_get_path('module', 'time_tracker') . '/views/css/time_tracker_views.css');
-  //   }
-  // }
-
-  if (isset($form['timestamp']['min']) && isset($form['timestamp']['max']) && arg(0) != 'admin') {
-
-    $start_date = urlencode($form['timestamp']['min']['#default_value']);
-    $end_date = urlencode($form['timestamp']['max']['#default_value']);
-
-    // Whaaaaa-aaaat?
-    // This is a simple redirect if there is no ? in the file path
-    // It's a hack, I know, but it works...
-    if ( !isset($_GET['uid']) && !isset($_GET['timestamp']['min']) && !isset($_GET['timestamp']['max']) &&  !isset($_GET['pid']) && !isset($_GET['group_nid']) ) {
-      drupal_goto($_GET['q'], 'timestamp[min]=' . $start_date . '&timestamp[max]=' . $end_date);
-    }
-
-  }
-}
-
-/**
- * Implementation of hook_date_api_tables
- */
-function time_tracker_date_api_tables() {
-  return array('time_tracker_entry');
-}
-
-/**
- * Implementation of hook_date_api_fields
- * This is required to allow timetracker timestamp
- * as a date argument in views.
- */
-function time_tracker_date_api_fields($field) {
-  $values = array(
-    'sql_type' => DATE_UNIX,
-    'tz_handling' => 'site',
-    'timezone_field' => '',
-    'offset_field' => '',
-    'related_fields' => array(),
-    'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
-  );
-
-  switch($field) {
-    case 'time_tracker_entry.timestamp':
-    case 'time_tracker_entry.start':
-    case 'time_tracker_entry.end':
-      return $values;
-  }
-}
-
-/**
- * Implementation of hook_views_bulk_operations_object_info().
- */
-function time_tracker_views_bulk_operations_object_info() {
-  $object_info = array(
-    'time_tracker_entry' => array(
-      'type' => 'time_tracker',
-      'base_table' => 'time_tracker_entry',
-      'load' => '_time_tracker_entry_load',
-      'oid' => 'teid',
-      'title' => 'title',
-    ),
-  );
-  return $object_info;
-}
-
-
-/**
- * Implementation of hook_action_info().
- */
-function time_tracker_action_info() {
-  return array(
-    'time_tracker_time_tracker_billed_action' => array(
-      'description' => t('Mark entries as billed'),
-      'type' => 'time_tracker',
-      'configurable' => FALSE,
-      'hooks' => array(
-        'time_tracker' => array('billed'),
-      ),
-    ),
-  );
-}
-
-
-/***********************************************************************
- * HELPER FUNCTIONS
- ***********************************************************************/
-
-
-function time_tracker_time_tracker_billed_action($teids, $context) {
-  foreach ($teids as $teid) {
-    db_query("UPDATE time_tracker_entry SET billed = 1 WHERE teid = %d", $teid);
-  }
-}
-
-function _time_tracker_entry_load($teid) {
-  return db_fetch_object(db_query("SELECT *, n.title FROM {time_tracker_entry} AS te JOIN {node} AS n ON te.nid = n.nid WHERE teid = %d", $teid));
-}
-
-
-/***********************************************************************
- * VIEWS CUSTOM JOIN HANDLERS
- ***********************************************************************/
-
-
-/**
- * Handles the join between the node table and the time information.
- *
- * Note that this handler is in the views.inc file rather than in its own file,
- * because we need to load it. Views doesn't auto-load join handlers, unlike
- * other handlers (i.e., join handlers are not Views handlers per se, despite
- * the name).
- */
-class time_tracker_node_join_handler extends views_join {
-
-  /**
-   * Overrides the views_join::join() method.
-   *
-   * Custom join that makes a sub-query.
-   */
-  function join($table, &$query) {
-    $alias = $table['alias'];
-    $left = $query->get_table_info('node');
-    $left_field = $left['alias'] . ".nid";
-
-    $output = $this->type . " JOIN (SELECT SUM(`duration`) - SUM(`deductions`) as total_time, `nid` FROM {time_tracker_entry} GROUP BY nid) as $alias ON $left_field = $alias.nid";
-    return $output;
-  }
-}
-
-/**
- * Handles the join between the time entry table and itself. Wait, what?
- *
- * We do this to create a new "Table" that defines the "total_duration" field
- * which is the duration minus the deductions. It's probably not the best
- * solution performance-wise, but it's compatible with views calc, and that's
- * more important for now. My original solution was a custom field handler
- * that overrode the query method. I kept it for now in:
- *   time_tracker_views_handler_field_total_duration.inc
- */
-class time_tracker_total_duration_join_handler extends views_join {
-
-  /**
-   * Overrides the views_join::join() method.
-   *
-   * Custom join that makes a sub-query.
-   */
-  function join($table, &$query) {
-    $alias = $table['alias'];
-    $left = $query->get_table_info('time_tracker_entry');
-    $left_field = $left['alias'] . ".teid";
-
-    $output = $this->type . " JOIN (SELECT duration - deductions as total_duration, teid FROM {time_tracker_entry}) as $alias ON $left_field = $alias.teid";
-    return $output;
-  }
-}
+<?php
+
+/**
+ * @file
+ *   Views integration for time_tracker
+ */
+
+/**
+ * Implements hook_views_data().
+ */
+function time_tracker_views_data() {
+  $data['time_tracker_entry']['table']['group'] = t('Time Tracker');
+  $data['time_tracker_entry']['table']['base'] = array(
+    'field' => 'teid',
+    'title' => t('Time Tracker'),
+    'help' => t('Content generated from time tracker entries.'),
+  );
+
+  $data['time_tracker_entry']['teid'] = array(
+    'title' => t('ID'),
+    'help' => t('Time Entry ID.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_numeric',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+
+  $data['time_tracker_entry']['timestamp'] = array(
+    'title' => t('Timestamp'),
+    'help' => t('Timestamp of the Entry.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'time_tracker_views_handler_filter_date',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['start'] = array(
+    'title' => t('Start Time'),
+    'help' => t('Start time of the Entry.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'time_tracker_views_handler_filter_date',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['end'] = array(
+    'title' => t('End Time'),
+    'help' => t('End time of the Entry.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'time_tracker_views_handler_filter_date',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['duration'] = array(
+    'title' => t('Duration'),
+    'help' => t('The Raw Time Entry Duration (without deductions).'),
+    'field' => array(
+      'handler' => 'time_tracker_views_handler_field_numeric',
+      'float' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['note'] = array(
+    'title' => t('Note'),
+    'help' => t('Notes for node-based time entries'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['deductions'] = array(
+    'title' => t('Deductions'),
+    'help' => t('Time Entry Deductions.'),
+    'field' => array(
+      'handler' => 'time_tracker_views_handler_field_numeric',
+      'float' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  // $data['time_tracker_entry']['total_duration'] = array(
+  //   'title' => t('Total Duration'),
+  //   'help' => t('Time Entry Total Duration, minus the deductions'),
+  //   'field' => array(
+  //     'handler' => 'time_tracker_views_handler_field_total_duration',
+  //     'float' => TRUE,
+  //   ),
+  //   'sort' => array(
+  //     'handler' => 'views_handler_sort',
+  //   ),
+  //   'filter' => array(
+  //     'handler' => 'views_handler_filter_numeric',
+  //   ),
+  //   'argument' => array(
+  //     'handler' => 'views_handler_argument',
+  //   ),
+  // );
+  // This isn't being used right now so I'm de-exposing it to views
+  $data['time_tracker_entry']['billable'] = array(
+    'title' => t('Billable'),
+    'help' => t('Is the Entry Billable?'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['billed'] = array(
+    'title' => t('Billed'),
+    'help' => t('Has the Entry been billed?'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['locked'] = array(
+    'title' => t('Locked'),
+    'help' => t('Is the Entry Locked?'),
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument',
+    ),
+  );
+  $data['time_tracker_entry']['uid'] = array(
+    'title' => t('Author'),
+    'help' => t('Relate an entry to the user who created it.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'users',
+      'base field' => 'uid',
+      'label' => t('User'),
+    ),
+  );
+  $data['time_tracker_entry']['nid'] = array(
+    'title' => t('Node'),
+    'help' => t('Relate an entry to a comments node.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'node',
+      'base field' => 'nid',
+      'label' => t('Node'),
+    ),
+  );
+  $data['time_tracker_entry']['cid'] = array(
+    'title' => t('Comment'),
+    'help' => t('Relate an entry to a comment.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'comments',
+      'base field' => 'cid',
+      'label' => t('Comment'),
+    ),
+  );
+  $data['time_tracker_entry']['activity'] = array(
+    'title' => t('Activity'),
+    'help' => t('Relate an entry to an Activity Name.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'time_tracker_activity',
+      'base field' => 'taid',
+      'label' => t('Activity'),
+    ),
+  );
+
+  $data['time_tracker_activity']['table']['join']['time_tracker_entry'] = array(
+    'left_field' => 'activity',
+    'field' => 'taid',
+  );
+  $data['time_tracker_activity']['table']['group'] = t('Time Tracker');
+
+  $data['time_tracker_activity']['name'] = array(
+    'title' => t('Activity Name'),
+    'help' => t('Activity Name.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  $data['time_estimate_entry']['table']['join']['time_tracker_entry'] = array(
+    'left_field' => 'nid',
+    'field' => 'nid',
+  );
+  $data['time_estimate_entry']['table']['group'] = t('Time Tracker');
+
+  $data['time_estimate_entry']['estimate'] = array(
+    'title' => t('Time Estimate'),
+    'help' => t('Time Estimate.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_numeric',
+    ),
+  );
+
+  // Access Time Tracker Data from the comments base table
+  $data['comments']['cid'] = array(
+    'relationship' => array(
+      'title' => t('Time Tracker'),
+      'help' => t('Access time tracker data for comments.'),
+      'handler' => 'views_handler_relationship',
+      'base' => 'time_tracker_entry',
+      'base field' => 'cid',
+      'label' => t('Time Tracker'),
+    ),
+  );
+
+  // Access Time Tracker Data from the node base table
+  $data['node']['nid'] = array(
+    'relationship' => array(
+      'title' => t('Time Tracker'),
+      'help' => t('Access time tracker data for nodes.'),
+      'handler' => 'views_handler_relationship',
+      'base' => 'time_tracker_entry',
+      'base field' => 'nid',
+      'label' => t('Time Tracker'),
+    ),
+  );
+
+  // Define a "table" called 'time_tracker_totals', which will actually be
+  // a subquery that will add up all the time tracked on the node.
+  $data['time_tracker_totals'] = array(
+    'table' => array(
+      'group' => t('Time Tracker'),
+      // Join this "table" to the Node table, so this can be used in node views,
+      // which is the whole point.
+      'join' => array(
+        'node' => array(
+          'left_field' => 'nid',
+          'field' => 'nid',
+          // Use a custom join handler, which constructs the query. This is
+          // defined below.
+          'handler' => 'time_tracker_node_join_handler',
+        ),
+      ),
+    ),
+
+    // Create a field called total_time, to add up all the time tracked on
+    // a node. Allow it to be used as a numeric Field, Filter, and Sort.
+    'total_time' => array(
+      'title' => t('Total time'),
+      'help' => t('The total time tracked on the node (minus deductions)'),
+      'field' => array(
+        'handler' => 'views_handler_field_numeric',
+        'click sortable' => TRUE,
+        'float' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+    ),
+  );
+
+  // Define another "table" called 'time_tracker_total_duration'.
+  // This one creates a compound field "total_duration" (duration - deduction)
+  // and joins it back into the time_tracker_entry table.
+  $data['time_tracker_total_duration'] = array(
+    'table' => array(
+      'group' => t('Time Tracker'),
+      // Join this "table" to the Node table, so this can be used in node views,
+      // which is the whole point.
+      'join' => array(
+        'time_tracker_entry' => array(
+          'left_field' => 'teid',
+          'field' => 'teid',
+          // Use a custom join handler, which constructs the query. This is
+          // defined below.
+          'handler' => 'time_tracker_total_duration_join_handler',
+        ),
+      ),
+    ),
+
+    // Create a field called total_duration, which is the duration minus the
+    // deductions. This belongs to the pseudo table "time_tracker_total_duration"
+    'total_duration' => array(
+      'title' => t('Total Duration'),
+      'help' => t('Time Entry Total Duration, minus the deductions'),
+      'field' => array(
+        'handler' => 'time_tracker_views_handler_field_numeric',
+        'click sortable' => TRUE,
+        'float' => TRUE,
+      ),
+      'filter' => array(
+        'handler' => 'views_handler_filter_numeric',
+      ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+      ),
+      'argument' => array(
+        'handler' => 'views_handler_argument',
+      ),
+    ),
+  );
+
+  return $data;
+}
+
+
+
+
+function time_tracker_form_views_exposed_form_alter(&$form, $form_state) {
+
+  // if ($form['form_id']['#id'] == 'edit-views-exposed-form') {
+  //   if(module_exists('jquery_ui')) {
+  //     jquery_ui_add(array('ui.datepicker'));
+  //     drupal_add_js(drupal_get_path('module', 'time_tracker') .'/js/datepicker.settings.js');
+  //     drupal_add_css(drupal_get_path('module', 'jquery_ui') .'/jquery.ui/themes/default/ui.datepicker.css');
+  //     drupal_add_css(drupal_get_path('module', 'time_tracker') . '/views/css/time_tracker_views.css');
+  //   }
+  // }
+
+  if (isset($form['timestamp']['min']) && isset($form['timestamp']['max']) && arg(0) != 'admin') {
+
+    $start_date = urlencode($form['timestamp']['min']['#default_value']);
+    $end_date = urlencode($form['timestamp']['max']['#default_value']);
+
+    // Whaaaaa-aaaat?
+    // This is a simple redirect if there is no ? in the file path
+    // It's a hack, I know, but it works...
+    if ( !isset($_GET['uid']) && !isset($_GET['timestamp']['min']) && !isset($_GET['timestamp']['max']) &&  !isset($_GET['pid']) && !isset($_GET['group_nid']) ) {
+      drupal_goto($_GET['q'], 'timestamp[min]=' . $start_date . '&timestamp[max]=' . $end_date);
+    }
+
+  }
+}
+
+/**
+ * Implements of hook_date_api_tables().
+ */
+function time_tracker_date_api_tables() {
+  return array('time_tracker_entry');
+}
+
+/**
+ * Implements hook_date_api_fields().
+ *
+ * This is required to allow timetracker timestamp
+ * as a date argument in views.
+ */
+function time_tracker_date_api_fields($field) {
+  $values = array(
+    'sql_type' => DATE_UNIX,
+    'tz_handling' => 'site',
+    'timezone_field' => '',
+    'offset_field' => '',
+    'related_fields' => array(),
+    'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
+  );
+
+  switch ($field) {
+    case 'time_tracker_entry.timestamp':
+    case 'time_tracker_entry.start':
+    case 'time_tracker_entry.end':
+      return $values;
+  }
+}
+
+/**
+ * Implements hook_views_bulk_operations_object_info().
+ */
+function time_tracker_views_bulk_operations_object_info() {
+  $object_info = array(
+    'time_tracker_entry' => array(
+      'type' => 'time_tracker',
+      'base_table' => 'time_tracker_entry',
+      'load' => '_time_tracker_entry_load',
+      'oid' => 'teid',
+      'title' => 'title',
+    ),
+  );
+  return $object_info;
+}
+
+/***********************************************************************
+ * VIEWS CUSTOM JOIN HANDLERS
+ ***********************************************************************/
+/**
+ * Handles the join between the node table and the time information.
+ *
+ * Note that this handler is in the views.inc file rather than in its own file,
+ * because we need to load it. Views doesn't auto-load join handlers, unlike
+ * other handlers (i.e., join handlers are not Views handlers per se, despite
+ * the name).
+ */
+class time_tracker_node_join_handler extends views_join {
+
+  /**
+   * Overrides the views_join::join() method.
+   *
+   * Custom join that makes a sub-query.
+   */
+  function join($table, &$query) {
+    $alias = $table['alias'];
+    $left = $query->get_table_info('node');
+    $left_field = $left['alias'] . ".nid";
+
+    $output = $this->type . " JOIN (SELECT SUM(`duration`) - SUM(`deductions`) as total_time, `nid` FROM {time_tracker_entry} GROUP BY nid) as $alias ON $left_field = $alias.nid";
+    return $output;
+  }
+}
+
+/**
+ * Handles the join between the time entry table and itself. Wait, what?
+ *
+ * We do this to create a new "Table" that defines the "total_duration" field
+ * which is the duration minus the deductions. It's probably not the best
+ * solution performance-wise, but it's compatible with views calc, and that's
+ * more important for now. My original solution was a custom field handler
+ * that overrode the query method. I kept it for now in:
+ *   time_tracker_views_handler_field_total_duration.inc
+ */
+class time_tracker_total_duration_join_handler extends views_join {
+
+  /**
+   * Overrides the views_join::join() method.
+   *
+   * Custom join that makes a sub-query.
+   */
+  function join($table, &$query) {
+    $alias = $table['alias'];
+    $left = $query->get_table_info('time_tracker_entry');
+    $left_field = $left['alias'] . ".teid";
+
+    $output = $this->type . " JOIN (SELECT duration - deductions as total_duration, teid FROM {time_tracker_entry}) as $alias ON $left_field = $alias.teid";
+    return $output;
+  }
+}
diff --git a/views/time_tracker.views_default.inc b/views/time_tracker.views_default.inc
index e551522..5a7128d 100644
--- a/views/time_tracker.views_default.inc
+++ b/views/time_tracker.views_default.inc
@@ -1,761 +1,761 @@
-<?php
-
-/**
- * @file
- * Implementation of hook_views_default_views().
- */
-function time_tracker_views_default_views() {
-  $list = array(
-    'time_tracker_reporting',
-  );
-  $views = array();
-  foreach ($list as $view_name) {
-    $view = call_user_func('_view_'. $view_name);
-    $views[$view->name] = $view;
-  }
-  return $views;
-}
-
-/**
- * The main time tracker reporting view
- */
-function _view_time_tracker_reporting() {
-  $view = new view;
-  $view->name = 'time_tracker_reports';
-  $view->description = 'A view for reporting on time tracker data.';
-  $view->tag = '';
-  $view->view_php = '';
-  $view->base_table = 'time_tracker_entry';
-  $view->is_cacheable = FALSE;
-  $view->api_version = 2;
-  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
-  $handler = $view->new_display('default', 'Defaults', 'default');
-  $handler->override_option('relationships', array(
-    'uid' => array(
-      'label' => 'User',
-      'required' => 0,
-      'id' => 'uid',
-      'table' => 'time_tracker_entry',
-      'field' => 'uid',
-      'relationship' => 'none',
-    ),
-    'cid' => array(
-      'label' => 'Comment',
-      'required' => 0,
-      'id' => 'cid',
-      'table' => 'time_tracker_entry',
-      'field' => 'cid',
-      'relationship' => 'none',
-    ),
-    'nid' => array(
-      'label' => 'Node',
-      'required' => 0,
-      'id' => 'nid',
-      'table' => 'time_tracker_entry',
-      'field' => 'nid',
-      'relationship' => 'none',
-    ),
-    'activity' => array(
-      'label' => 'Activity',
-      'required' => 0,
-      'id' => 'activity',
-      'table' => 'time_tracker_entry',
-      'field' => 'activity',
-      'override' => array(
-        'button' => 'Override',
-      ),
-      'relationship' => 'none',
-    ),
-    'pid' => array(
-      'label' => 'project',
-      'required' => 0,
-      'id' => 'pid',
-      'table' => 'casetracker_case',
-      'field' => 'pid',
-      'relationship' => 'nid',
-    ),
-  ));
-  $handler->override_option('fields', array(
-    'name' => array(
-      'label' => 'Name',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_user' => 1,
-      'overwrite_anonymous' => 0,
-      'anonymous_text' => '',
-      'exclude' => 0,
-      'id' => 'name',
-      'table' => 'users',
-      'field' => 'name',
-      'relationship' => 'uid',
-      'override' => array(
-        'button' => 'Override',
-      ),
-    ),
-    'title_1' => array(
-      'label' => 'Project',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'strip_tags' => 0,
-        'html' => 0,
-      ),
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'title_1',
-      'table' => 'node',
-      'field' => 'title',
-      'relationship' => 'nid',
-    ),
-    'title' => array(
-      'label' => 'Title',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'strip_tags' => 0,
-        'html' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'title',
-      'table' => 'node',
-      'field' => 'title',
-      'relationship' => 'nid',
-    ),
-    'comment' => array(
-      'label' => 'Body',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 1,
-        'max_length' => '200',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'exclude' => 0,
-      'id' => 'comment',
-      'table' => 'comments',
-      'field' => 'comment',
-      'relationship' => 'cid',
-    ),
-    'note' => array(
-      'label' => '',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'exclude' => 0,
-      'id' => 'note',
-      'table' => 'time_tracker_entry',
-      'field' => 'note',
-      'override' => array(
-        'button' => 'Override',
-      ),
-      'relationship' => 'none',
-    ),
-    'timestamp' => array(
-      'label' => 'Timestamp',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'date_format' => 'custom',
-      'custom_date_format' => 'M jS, Y',
-      'reldate' => '0',
-      'exclude' => 0,
-      'id' => 'timestamp',
-      'table' => 'time_tracker_entry',
-      'field' => 'timestamp',
-      'relationship' => 'none',
-    ),
-    'duration' => array(
-      'label' => 'Duration',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'strip_tags' => 0,
-        'html' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'set_precision' => FALSE,
-      'precision' => 0,
-      'decimal' => '.',
-      'separator' => ',',
-      'prefix' => '',
-      'suffix' => ' hours',
-      'exclude' => 0,
-      'id' => 'duration',
-      'table' => 'time_tracker_entry',
-      'field' => 'duration',
-      'relationship' => 'none',
-    ),
-  ));
-  $handler->override_option('sorts', array(
-    'timestamp' => array(
-      'id' => 'timestamp',
-      'table' => 'time_tracker_entry',
-      'field' => 'timestamp',
-    ),
-  ));
-  $handler->override_option('filters', array(
-    'uid' => array(
-      'operator' => 'in',
-      'value' => '',
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'uid_op',
-        'identifier' => 'uid',
-        'label' => 'Name',
-        'optional' => 1,
-        'remember' => 0,
-        'reduce' => 0,
-      ),
-      'id' => 'uid',
-      'table' => 'users',
-      'field' => 'uid',
-      'relationship' => 'uid',
-    ),
-    'timestamp' => array(
-      'operator' => 'between',
-      'value' => array(
-        'type' => 'relative',
-        'value' => '',
-        'min' => 'First Of This Month',
-        'max' => 'Last Of This Month',
-      ),
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'timestamp_op',
-        'identifier' => 'timestamp',
-        'label' => 'Entered Between',
-        'optional' => 1,
-        'remember' => 0,
-      ),
-      'id' => 'timestamp',
-      'table' => 'time_tracker_entry',
-      'field' => 'timestamp',
-      'relationship' => 'none',
-      'override' => array(
-        'button' => 'Override',
-      ),
-    ),
-    'pid' => array(
-      'operator' => 'or',
-      'value' => array(),
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'pid_op',
-        'identifier' => 'pid',
-        'label' => 'Project',
-        'optional' => 1,
-        'single' => 1,
-        'remember' => 0,
-        'reduce' => 0,
-      ),
-      'id' => 'pid',
-      'table' => 'casetracker_case',
-      'field' => 'pid',
-      'relationship' => 'nid',
-      'reduce_duplicates' => 0,
-    ),
-  ));
-  $handler->override_option('access', array(
-    'type' => 'role',
-    'role' => array(
-      '4' => 4,
-    ),
-  ));
-  $handler->override_option('cache', array(
-    'type' => 'none',
-  ));
-  $handler->override_option('items_per_page', 0);
-  $handler->override_option('style_plugin', 'views_calc');
-  $handler->override_option('style_options', array(
-    'grouping' => '',
-    'override' => 1,
-    'sticky' => 0,
-    'order' => 'asc',
-    'columns' => array(
-      'name' => 'name',
-      'title' => 'title',
-      'comment' => 'comment',
-      'note' => 'comment',
-      'timestamp' => 'timestamp',
-      'duration' => 'duration',
-    ),
-    'info' => array(
-      'name' => array(
-        'sortable' => 0,
-        'separator' => '<br/>',
-        'justification' => 'views_calc_justify_none',
-        'has_calc' => 0,
-        'calc' => array(),
-      ),
-      'title' => array(
-        'sortable' => 0,
-        'separator' => '',
-        'justification' => 'views_calc_justify_none',
-        'has_calc' => 0,
-        'calc' => array(),
-      ),
-      'comment' => array(
-        'separator' => '',
-        'justification' => 'views_calc_justify_none',
-        'has_calc' => 0,
-        'calc' => array(),
-      ),
-      'note' => array(
-        'separator' => '',
-        'justification' => 'views_calc_justify_none',
-        'has_calc' => 0,
-        'calc' => array(),
-      ),
-      'timestamp' => array(
-        'separator' => '',
-        'justification' => 'views_calc_justify_none',
-        'has_calc' => 0,
-        'calc' => array(),
-      ),
-      'duration' => array(
-        'separator' => '',
-        'justification' => 'views_calc_justify_none',
-        'has_calc' => 1,
-        'calc' => array(
-          'SUM' => 'SUM',
-        ),
-      ),
-    ),
-    'default' => '-1',
-    'detailed_values' => '0',
-  ));
-  $handler = $view->new_display('page', 'Page w/Casetracker', 'page_1');
-  $handler->override_option('path', 'time_tracker/casetracker_reports');
-  $handler->override_option('menu', array(
-    'type' => 'none',
-    'title' => '',
-    'description' => '',
-    'weight' => 0,
-    'name' => 'navigation',
-  ));
-  $handler->override_option('tab_options', array(
-    'type' => 'none',
-    'title' => '',
-    'description' => '',
-    'weight' => 0,
-    'name' => 'navigation',
-  ));
-  $handler = $view->new_display('page', 'Page', 'page_2');
-  $handler->override_option('relationships', array(
-    'uid' => array(
-      'label' => 'User',
-      'required' => 0,
-      'id' => 'uid',
-      'table' => 'time_tracker_entry',
-      'field' => 'uid',
-      'relationship' => 'none',
-    ),
-    'cid' => array(
-      'label' => 'Comment',
-      'required' => 0,
-      'id' => 'cid',
-      'table' => 'time_tracker_entry',
-      'field' => 'cid',
-      'relationship' => 'none',
-    ),
-    'nid' => array(
-      'label' => 'Node',
-      'required' => 0,
-      'id' => 'nid',
-      'table' => 'time_tracker_entry',
-      'field' => 'nid',
-      'relationship' => 'none',
-    ),
-    'activity' => array(
-      'label' => 'Activity',
-      'required' => 0,
-      'id' => 'activity',
-      'table' => 'time_tracker_entry',
-      'field' => 'activity',
-      'override' => array(
-        'button' => 'Override',
-      ),
-      'relationship' => 'none',
-    ),
-  ));
-  $handler->override_option('fields', array(
-    'name' => array(
-      'label' => 'Name',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_user' => 1,
-      'overwrite_anonymous' => 0,
-      'anonymous_text' => '',
-      'exclude' => 0,
-      'id' => 'name',
-      'table' => 'users',
-      'field' => 'name',
-      'relationship' => 'uid',
-      'override' => array(
-        'button' => 'Override',
-      ),
-    ),
-    'title' => array(
-      'label' => 'Title',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'strip_tags' => 0,
-        'html' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'link_to_node' => 1,
-      'exclude' => 0,
-      'id' => 'title',
-      'table' => 'node',
-      'field' => 'title',
-      'relationship' => 'nid',
-    ),
-    'comment' => array(
-      'label' => 'Body',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 1,
-        'max_length' => '200',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'exclude' => 0,
-      'id' => 'comment',
-      'table' => 'comments',
-      'field' => 'comment',
-      'relationship' => 'cid',
-    ),
-    'note' => array(
-      'label' => '',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'exclude' => 0,
-      'id' => 'note',
-      'table' => 'time_tracker_entry',
-      'field' => 'note',
-      'override' => array(
-        'button' => 'Use default',
-      ),
-      'relationship' => 'none',
-    ),
-    'timestamp' => array(
-      'label' => 'Timestamp',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'html' => 0,
-        'strip_tags' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'date_format' => 'custom',
-      'custom_date_format' => 'M jS, Y',
-      'reldate' => '0',
-      'exclude' => 0,
-      'id' => 'timestamp',
-      'table' => 'time_tracker_entry',
-      'field' => 'timestamp',
-      'relationship' => 'none',
-    ),
-    'duration' => array(
-      'label' => 'Duration',
-      'alter' => array(
-        'alter_text' => 0,
-        'text' => '',
-        'make_link' => 0,
-        'path' => '',
-        'link_class' => '',
-        'alt' => '',
-        'prefix' => '',
-        'suffix' => '',
-        'target' => '',
-        'help' => '',
-        'trim' => 0,
-        'max_length' => '',
-        'word_boundary' => 1,
-        'ellipsis' => 1,
-        'strip_tags' => 0,
-        'html' => 0,
-      ),
-      'empty' => '',
-      'hide_empty' => 0,
-      'empty_zero' => 0,
-      'set_precision' => FALSE,
-      'precision' => 0,
-      'decimal' => '.',
-      'separator' => ',',
-      'prefix' => '',
-      'suffix' => ' hours',
-      'exclude' => 0,
-      'id' => 'duration',
-      'table' => 'time_tracker_entry',
-      'field' => 'duration',
-      'relationship' => 'none',
-    ),
-  ));
-  $handler->override_option('filters', array(
-    'uid' => array(
-      'operator' => 'in',
-      'value' => '',
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'uid_op',
-        'identifier' => 'uid',
-        'label' => 'Name',
-        'optional' => 1,
-        'remember' => 0,
-        'reduce' => 0,
-      ),
-      'id' => 'uid',
-      'table' => 'users',
-      'field' => 'uid',
-      'relationship' => 'uid',
-    ),
-    'timestamp' => array(
-      'operator' => 'between',
-      'value' => array(
-        'type' => 'relative',
-        'value' => '',
-        'min' => 'First Of This Month',
-        'max' => 'Last Of This Month',
-      ),
-      'group' => '0',
-      'exposed' => TRUE,
-      'expose' => array(
-        'use_operator' => 0,
-        'operator' => 'timestamp_op',
-        'identifier' => 'timestamp',
-        'label' => 'Entered Between',
-        'optional' => 1,
-        'remember' => 0,
-      ),
-      'id' => 'timestamp',
-      'table' => 'time_tracker_entry',
-      'field' => 'timestamp',
-      'relationship' => 'none',
-      'override' => array(
-        'button' => 'Override',
-      ),
-    ),
-  ));
-  $handler->override_option('path', 'time_tracker/reports');
-  $handler->override_option('menu', array(
-    'type' => 'none',
-    'title' => '',
-    'description' => '',
-    'weight' => 0,
-    'name' => 'navigation',
-  ));
-  $handler->override_option('tab_options', array(
-    'type' => 'none',
-    'title' => '',
-    'description' => '',
-    'weight' => 0,
-    'name' => 'navigation',
-  ));
-  $translatables['time_tracker_reports'] = array(
-    t('Defaults'),
-    t('Page'),
-    t('Page w/Casetracker'),
-  );
-  
-  return $view;
+<?php
+
+/**
+ * @file
+ * Implements hook_views_default_views().
+ */
+function time_tracker_views_default_views() {
+  $list = array(
+    'time_tracker_reporting',
+  );
+  $views = array();
+  foreach ($list as $view_name) {
+    $view = call_user_func('_view_' . $view_name);
+    $views[$view->name] = $view;
+  }
+  return $views;
+}
+
+/**
+ * The main time tracker reporting view
+ */
+function _view_time_tracker_reporting() {
+  $view = new view;
+  $view->name = 'time_tracker_reports';
+  $view->description = 'A view for reporting on time tracker data.';
+  $view->tag = '';
+  $view->view_php = '';
+  $view->base_table = 'time_tracker_entry';
+  $view->is_cacheable = FALSE;
+  $view->api_version = 2;
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+  $handler = $view->new_display('default', 'Defaults', 'default');
+  $handler->override_option('relationships', array(
+    'uid' => array(
+      'label' => 'User',
+      'required' => 0,
+      'id' => 'uid',
+      'table' => 'time_tracker_entry',
+      'field' => 'uid',
+      'relationship' => 'none',
+    ),
+    'cid' => array(
+      'label' => 'Comment',
+      'required' => 0,
+      'id' => 'cid',
+      'table' => 'time_tracker_entry',
+      'field' => 'cid',
+      'relationship' => 'none',
+    ),
+    'nid' => array(
+      'label' => 'Node',
+      'required' => 0,
+      'id' => 'nid',
+      'table' => 'time_tracker_entry',
+      'field' => 'nid',
+      'relationship' => 'none',
+    ),
+    'activity' => array(
+      'label' => 'Activity',
+      'required' => 0,
+      'id' => 'activity',
+      'table' => 'time_tracker_entry',
+      'field' => 'activity',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+    'pid' => array(
+      'label' => 'project',
+      'required' => 0,
+      'id' => 'pid',
+      'table' => 'casetracker_case',
+      'field' => 'pid',
+      'relationship' => 'nid',
+    ),
+  ));
+  $handler->override_option('fields', array(
+    'name' => array(
+      'label' => 'Name',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'link_to_user' => 1,
+      'overwrite_anonymous' => 0,
+      'anonymous_text' => '',
+      'exclude' => 0,
+      'id' => 'name',
+      'table' => 'users',
+      'field' => 'name',
+      'relationship' => 'uid',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+    'title_1' => array(
+      'label' => 'Project',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'link_to_node' => 1,
+      'exclude' => 0,
+      'id' => 'title_1',
+      'table' => 'node',
+      'field' => 'title',
+      'relationship' => 'nid',
+    ),
+    'title' => array(
+      'label' => 'Title',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'link_to_node' => 1,
+      'exclude' => 0,
+      'id' => 'title',
+      'table' => 'node',
+      'field' => 'title',
+      'relationship' => 'nid',
+    ),
+    'comment' => array(
+      'label' => 'Body',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 1,
+        'max_length' => '200',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'comment',
+      'table' => 'comments',
+      'field' => 'comment',
+      'relationship' => 'cid',
+    ),
+    'note' => array(
+      'label' => '',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'note',
+      'table' => 'time_tracker_entry',
+      'field' => 'note',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+    'timestamp' => array(
+      'label' => 'Timestamp',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'date_format' => 'custom',
+      'custom_date_format' => 'M jS, Y',
+      'reldate' => '0',
+      'exclude' => 0,
+      'id' => 'timestamp',
+      'table' => 'time_tracker_entry',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+    ),
+    'duration' => array(
+      'label' => 'Duration',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'set_precision' => FALSE,
+      'precision' => 0,
+      'decimal' => '.',
+      'separator' => ',',
+      'prefix' => '',
+      'suffix' => ' hours',
+      'exclude' => 0,
+      'id' => 'duration',
+      'table' => 'time_tracker_entry',
+      'field' => 'duration',
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('sorts', array(
+    'timestamp' => array(
+      'id' => 'timestamp',
+      'table' => 'time_tracker_entry',
+      'field' => 'timestamp',
+    ),
+  ));
+  $handler->override_option('filters', array(
+    'uid' => array(
+      'operator' => 'in',
+      'value' => '',
+      'group' => '0',
+      'exposed' => TRUE,
+      'expose' => array(
+        'use_operator' => 0,
+        'operator' => 'uid_op',
+        'identifier' => 'uid',
+        'label' => 'Name',
+        'optional' => 1,
+        'remember' => 0,
+        'reduce' => 0,
+      ),
+      'id' => 'uid',
+      'table' => 'users',
+      'field' => 'uid',
+      'relationship' => 'uid',
+    ),
+    'timestamp' => array(
+      'operator' => 'between',
+      'value' => array(
+        'type' => 'relative',
+        'value' => '',
+        'min' => 'First Of This Month',
+        'max' => 'Last Of This Month',
+      ),
+      'group' => '0',
+      'exposed' => TRUE,
+      'expose' => array(
+        'use_operator' => 0,
+        'operator' => 'timestamp_op',
+        'identifier' => 'timestamp',
+        'label' => 'Entered Between',
+        'optional' => 1,
+        'remember' => 0,
+      ),
+      'id' => 'timestamp',
+      'table' => 'time_tracker_entry',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+    'pid' => array(
+      'operator' => 'or',
+      'value' => array(),
+      'group' => '0',
+      'exposed' => TRUE,
+      'expose' => array(
+        'use_operator' => 0,
+        'operator' => 'pid_op',
+        'identifier' => 'pid',
+        'label' => 'Project',
+        'optional' => 1,
+        'single' => 1,
+        'remember' => 0,
+        'reduce' => 0,
+      ),
+      'id' => 'pid',
+      'table' => 'casetracker_case',
+      'field' => 'pid',
+      'relationship' => 'nid',
+      'reduce_duplicates' => 0,
+    ),
+  ));
+  $handler->override_option('access', array(
+    'type' => 'role',
+    'role' => array(
+      '4' => 4,
+    ),
+  ));
+  $handler->override_option('cache', array(
+    'type' => 'none',
+  ));
+  $handler->override_option('items_per_page', 0);
+  $handler->override_option('style_plugin', 'views_calc');
+  $handler->override_option('style_options', array(
+    'grouping' => '',
+    'override' => 1,
+    'sticky' => 0,
+    'order' => 'asc',
+    'columns' => array(
+      'name' => 'name',
+      'title' => 'title',
+      'comment' => 'comment',
+      'note' => 'comment',
+      'timestamp' => 'timestamp',
+      'duration' => 'duration',
+    ),
+    'info' => array(
+      'name' => array(
+        'sortable' => 0,
+        'separator' => '<br/>',
+        'justification' => 'views_calc_justify_none',
+        'has_calc' => 0,
+        'calc' => array(),
+      ),
+      'title' => array(
+        'sortable' => 0,
+        'separator' => '',
+        'justification' => 'views_calc_justify_none',
+        'has_calc' => 0,
+        'calc' => array(),
+      ),
+      'comment' => array(
+        'separator' => '',
+        'justification' => 'views_calc_justify_none',
+        'has_calc' => 0,
+        'calc' => array(),
+      ),
+      'note' => array(
+        'separator' => '',
+        'justification' => 'views_calc_justify_none',
+        'has_calc' => 0,
+        'calc' => array(),
+      ),
+      'timestamp' => array(
+        'separator' => '',
+        'justification' => 'views_calc_justify_none',
+        'has_calc' => 0,
+        'calc' => array(),
+      ),
+      'duration' => array(
+        'separator' => '',
+        'justification' => 'views_calc_justify_none',
+        'has_calc' => 1,
+        'calc' => array(
+          'SUM' => 'SUM',
+        ),
+      ),
+    ),
+    'default' => '-1',
+    'detailed_values' => '0',
+  ));
+  $handler = $view->new_display('page', 'Page w/Casetracker', 'page_1');
+  $handler->override_option('path', 'time_tracker/casetracker_reports');
+  $handler->override_option('menu', array(
+    'type' => 'none',
+    'title' => '',
+    'description' => '',
+    'weight' => 0,
+    'name' => 'navigation',
+  ));
+  $handler->override_option('tab_options', array(
+    'type' => 'none',
+    'title' => '',
+    'description' => '',
+    'weight' => 0,
+    'name' => 'navigation',
+  ));
+  $handler = $view->new_display('page', 'Page', 'page_2');
+  $handler->override_option('relationships', array(
+    'uid' => array(
+      'label' => 'User',
+      'required' => 0,
+      'id' => 'uid',
+      'table' => 'time_tracker_entry',
+      'field' => 'uid',
+      'relationship' => 'none',
+    ),
+    'cid' => array(
+      'label' => 'Comment',
+      'required' => 0,
+      'id' => 'cid',
+      'table' => 'time_tracker_entry',
+      'field' => 'cid',
+      'relationship' => 'none',
+    ),
+    'nid' => array(
+      'label' => 'Node',
+      'required' => 0,
+      'id' => 'nid',
+      'table' => 'time_tracker_entry',
+      'field' => 'nid',
+      'relationship' => 'none',
+    ),
+    'activity' => array(
+      'label' => 'Activity',
+      'required' => 0,
+      'id' => 'activity',
+      'table' => 'time_tracker_entry',
+      'field' => 'activity',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('fields', array(
+    'name' => array(
+      'label' => 'Name',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'link_to_user' => 1,
+      'overwrite_anonymous' => 0,
+      'anonymous_text' => '',
+      'exclude' => 0,
+      'id' => 'name',
+      'table' => 'users',
+      'field' => 'name',
+      'relationship' => 'uid',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+    'title' => array(
+      'label' => 'Title',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'link_to_node' => 1,
+      'exclude' => 0,
+      'id' => 'title',
+      'table' => 'node',
+      'field' => 'title',
+      'relationship' => 'nid',
+    ),
+    'comment' => array(
+      'label' => 'Body',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 1,
+        'max_length' => '200',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'comment',
+      'table' => 'comments',
+      'field' => 'comment',
+      'relationship' => 'cid',
+    ),
+    'note' => array(
+      'label' => '',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'note',
+      'table' => 'time_tracker_entry',
+      'field' => 'note',
+      'override' => array(
+        'button' => 'Use default',
+      ),
+      'relationship' => 'none',
+    ),
+    'timestamp' => array(
+      'label' => 'Timestamp',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'html' => 0,
+        'strip_tags' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'date_format' => 'custom',
+      'custom_date_format' => 'M jS, Y',
+      'reldate' => '0',
+      'exclude' => 0,
+      'id' => 'timestamp',
+      'table' => 'time_tracker_entry',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+    ),
+    'duration' => array(
+      'label' => 'Duration',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'set_precision' => FALSE,
+      'precision' => 0,
+      'decimal' => '.',
+      'separator' => ',',
+      'prefix' => '',
+      'suffix' => ' hours',
+      'exclude' => 0,
+      'id' => 'duration',
+      'table' => 'time_tracker_entry',
+      'field' => 'duration',
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('filters', array(
+    'uid' => array(
+      'operator' => 'in',
+      'value' => '',
+      'group' => '0',
+      'exposed' => TRUE,
+      'expose' => array(
+        'use_operator' => 0,
+        'operator' => 'uid_op',
+        'identifier' => 'uid',
+        'label' => 'Name',
+        'optional' => 1,
+        'remember' => 0,
+        'reduce' => 0,
+      ),
+      'id' => 'uid',
+      'table' => 'users',
+      'field' => 'uid',
+      'relationship' => 'uid',
+    ),
+    'timestamp' => array(
+      'operator' => 'between',
+      'value' => array(
+        'type' => 'relative',
+        'value' => '',
+        'min' => 'First Of This Month',
+        'max' => 'Last Of This Month',
+      ),
+      'group' => '0',
+      'exposed' => TRUE,
+      'expose' => array(
+        'use_operator' => 0,
+        'operator' => 'timestamp_op',
+        'identifier' => 'timestamp',
+        'label' => 'Entered Between',
+        'optional' => 1,
+        'remember' => 0,
+      ),
+      'id' => 'timestamp',
+      'table' => 'time_tracker_entry',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+  ));
+  $handler->override_option('path', 'time_tracker/reports');
+  $handler->override_option('menu', array(
+    'type' => 'none',
+    'title' => '',
+    'description' => '',
+    'weight' => 0,
+    'name' => 'navigation',
+  ));
+  $handler->override_option('tab_options', array(
+    'type' => 'none',
+    'title' => '',
+    'description' => '',
+    'weight' => 0,
+    'name' => 'navigation',
+  ));
+  $translatables['time_tracker_reports'] = array(
+    t('Defaults'),
+    t('Page'),
+    t('Page w/Casetracker'),
+  );
+
+  return $view;
 }
\ No newline at end of file
diff --git a/views/time_tracker_views_handler_field_numeric.inc b/views/time_tracker_views_handler_field_numeric.inc
index 9263766..ca307c6 100644
--- a/views/time_tracker_views_handler_field_numeric.inc
+++ b/views/time_tracker_views_handler_field_numeric.inc
@@ -46,7 +46,7 @@ class time_tracker_views_handler_field_numeric extends views_handler_field_numer
         $saved_values->{$this->field_alias} = round($value * 60);
       }
       elseif ($this->options['output_format'] == 'seconds') {
-         $saved_values->{$this->field_alias} = round($value * 60 * 60);
+        $saved_values->{$this->field_alias} = round($value * 60 * 60);
       }
       return parent::render($saved_values);
     }
diff --git a/views/time_tracker_views_handler_filter_date.inc b/views/time_tracker_views_handler_filter_date.inc
index 7014fcb..489e05a 100644
--- a/views/time_tracker_views_handler_filter_date.inc
+++ b/views/time_tracker_views_handler_filter_date.inc
@@ -238,26 +238,26 @@ class time_tracker_views_handler_filter_date extends views_handler_filter_numeri
     $value = strtolower($value);
     switch ($value) {
       case 'first of this month':
-        $timestamp = strtotime(date('m').'/01/'.date('Y'));
+        $timestamp = strtotime(date('m') . '/01/' . date('Y'));
         break;
       case 'last of this month':
-        $timestamp = strtotime('-1 hour',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y'))));;
+        $timestamp = strtotime('-1 hour',strtotime('+1 month',strtotime(date('m') . '/01/' . date('Y'))));;
         break;
       case 'bimonthly':
         if ($limit == 'min') {
           if (date('j') < 16) {
-            $timestamp = strtotime(date('m').'/01/'.date('Y'));
+            $timestamp = strtotime(date('m') . '/01/' . date('Y'));
           }
           else {
-            $timestamp = strtotime(date('m').'/16/'.date('Y'));
+            $timestamp = strtotime(date('m') . '/16/' . date('Y'));
           }
         }
         else {
           if (date('j') < 16) {
-            $timestamp = strtotime(date('m').'/15/'.date('Y'));
+            $timestamp = strtotime(date('m') . '/15/' . date('Y'));
           }
           else {
-            $timestamp = strtotime('-1 hour',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y'))));
+            $timestamp = strtotime('-1 hour',strtotime('+1 month',strtotime(date('m') . '/01/' . date('Y'))));
           }
         }
         break;
@@ -268,7 +268,7 @@ class time_tracker_views_handler_filter_date extends views_handler_filter_numeri
           preg_match('/[0-9]+/', $value, $matches);
           if (isset($matches[0]) && is_numeric($matches[0])) {
             if (preg_match('/this month/', $value)) {
-              $timestamp = strtotime(date('m').'/'.$matches[0].'/'.date('Y'));
+              $timestamp = strtotime(date('m') . '/' . $matches[0] . '/' . date('Y'));
             }
           }
         }
