--- todolist.module	Sun Oct 28 18:39:57 2007
+++ todolist.module	Sun Jul 20 22:42:53 2008
@@ -1,359 +1,434 @@
-<?php
-// $Id: todolist.module,v 1.5 2007/10/28 23:39:57 mikesmullin Exp $
-
-/**
- * Implementation of hook_node_info().
- */
-function todolist_node_info() {
-  return array(
-    'todolist' => array(
-      'name' => t('Todolist'),
-      'module' => 'todolist',
-      'description' => t('Create a new todolist.'),
-    )
-  );
-}
-
-/**
- * Implementation of hook_perm().
- */
-function todolist_perm() {
-  return array('create tasks', 'complete tasks', 'uncomplete tasks', 'reorder tasks', 'delete tasks', 'edit own tasks', 'edit tasks');
-}
-
-/**
- * Implementation of hook_menu().
- */
-function todolist_menu($may_cache) {
-  $items = array();
-
-  if ($may_cache) {
-  } else  {
-    $items[] = array(
-      'path' => 'node/add/todolist',
-      'title' => t('Todolist'),
-      'access' => TRUE,
-    );
-    $items[] = array(
-      'path' => 'todolist/create_task',
-      'callback' => 'todolist_create_task',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'todolist/edit_task',
-      'callback' => 'todolist_edit_task',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'todolist/toggle_task',
-      'callback' => 'todolist_toggle_task',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'todolist/reorder_task',
-      'callback' => 'todolist_reorder_task',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'todolist/delete_task',
-      'callback' => 'todolist_delete_task',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-  }
-
-  return $items;
-}
-
-/**
- * Implementation of hook_form().
- */
-function todolist_form(&$node) {
-  return array(
-    'title' => array(
-      '#type' => 'textfield',
-      '#title' => t('Title'),
-      '#required' => TRUE,
-      '#default_value' => $node->title,
-      '#weight' => -4,
-    ),
-    'body' => array(
-      '#type' => 'textarea',
-      '#title' => t('Description'),
-      '#required' => FALSE,
-      '#default_value' => $node->body,
-    ),
-  );
-}
-
-/**
- * Add todolist JavaScript library to the current page.
- */
-function todolist_add_js() {
-  static $done;
-  if (!isset($done)) {
-    drupal_add_js(drupal_get_path('module', 'todolist') . '/todolist.js');
-    $done = TRUE;
-  }
-}
-
-/**
- * Add todolist JavaScript library to the current page.
- */
-function todolist_add_css() {
-  static $done;
-  if (!isset($done)) {
-    drupal_add_js(drupal_get_path('module', 'todolist') . '/todolist.js');
-    $done = TRUE;
-  }
-}
-
-/**
- * Implementation of hook_view().
- */
-function todolist_view(&$node, $teaser = FALSE, $page = FALSE) {
-  if ($page) {
-    jquery_interface_add();
-    todolist_add_js();
-    drupal_add_css(drupal_get_path('module', 'todolist') . '/todolist.css', 'module');
-
-    $node->content['todolist'] = array('#value' => theme('todolist', $node));
-  }
-
-  return node_prepare($node, $teaser);
-}
-
-/**
- * Generate a Todolist.
- */
-function theme_todolist(&$node) {
-  $results = db_query("SELECT tid, status, task FROM {todolist_task} WHERE nid = %d ORDER BY status, `order`;", $node->nid);
-  while ($task = db_fetch_object($results)) {
-    $tasks[($task->status? 'complete' : 'incomplete')][] = theme('todolist_task', $task);
-  }
-  $output .= theme('item_list', $tasks['incomplete'], NULL, 'ul', array('id' => 'todolist-' . $node->nid, 'class' => 'todolist incomplete'));
-  $output .= drupal_get_form('todolist_add_task_form', $node);
-  $output .= theme('item_list', $tasks['complete'], NULL, 'ul', array('class' => 'todolist complete'));
-
-  return $output;
-}
-
-/**
- * Generate a Todolist Task.
- */
-function theme_todolist_task(&$task) {
-  return array(
-    'data' => '<input type="checkbox" name="task-'. $task->tid .'"'. ($task->status? 'checked' : '') .' /> ' . ($task->status? '<a href="javascript:void(0)" title="Delete this task" class="delete" onclick="return TodoList.delete_task(\'task-'. $task->tid .'\')">Delete</a> <span>'. date('M d', $task->status) .'</span> ' : '') . $task->task,
-    'class' => 'task',
-    'id' => 'task-'. $task->tid,
-  );
-}
-
-/**
- * Generate an Add Task form.
- *
- * @return Array $form
- *   Forms API form array.
- */
-function todolist_add_task_form(&$node) {
-  return array(
-    '#action' => url('todolist/create_task'),
-    array(
-      '#type' => 'fieldset',
-      '#title' => t('Add new task'),
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE,
-      'task' => array(
-        '#type' => 'textfield',
-        '#title' => t('Task'),
-        '#default_value' => '',
-        '#maxlength' => 255,
-        '#required' => TRUE,
-      ),
-      'submit' => array(
-        '#type' => 'submit',
-        '#value' => t('Add this task'),
-      ),
-      'nid' => array(
-        '#type' => 'hidden',
-        '#value' => $node->nid,
-      ),
-    ),
-  );
-}
-
-/**
- * Generate an Edit Task form.
- *
- * @return Array $form
- *   Forms API form array.
- */
-function todolist_edit_task_form(&$task) {
-  return array(
-    '#action' => url('todolist/edit_task'),
-    array(
-      'task' => array(
-        '#type' => 'textarea',
-        '#default_value' => $task->task,
-        '#required' => TRUE,
-      ),
-      'submit' => array(
-        '#type' => 'submit',
-        '#value' => t('Save this task'),
-      ),
-      'tid' => array(
-        '#type' => 'hidden',
-        '#value' => $task->tid,
-      ),
-    ),
-  );
-}
-
-/**
- * Check user_access and notify the browser of a forbidden request, if necessary.
- *
- * The server understood the request, but is refusing to fulfill it.
- * Authorization will not help and the request SHOULD NOT be repeated.
- *
- * @param String $perm ...
- *   The permission being checked for.
- */
-function todolist_user_access() {
-  if (user_access($perm)) { return TRUE; }
-
-  drupal_set_header('Status:403 Forbidden');
-  exit;
-}
-
-/**
- * Notify the browser of a bad request.
- *
- * The request could not be understood by the server due to malformed syntax.
- * The client SHOULD NOT repeat the request without modifications.
- */
-function todolist_bad_request() {
-  drupal_set_header('Status:400 Bad Request');
-  exit;
-}
-
-/**
- * Output JavaScript Content-Type headers.
- */
-function todolist_ok_js() {
-  drupal_set_header('Status:200 OK');
-  drupal_set_header('Content-Type:text/javascript');
-}
-
-/**
- * Escape single-quotes in a string.
- *
- * @param String $txt
- *   A string to be used in JavaScript.
- * @return String
- *   An escaped string.
- */
-function _todolist_js_safe($txt) {
-  $txt = str_replace("'", "\'", $txt);
-  $txt = preg_replace('/[\r\n]+/', '', $txt);
-  return $txt;
-}
-
-/**
- * MENU_CALLBACK function for /todolist/create_task.
- */
-function todolist_create_task() {
-  if (todolist_user_access('create tasks'))
-  if (isset($_REQUEST['nid']) && isset($_REQUEST['order']) && isset($_REQUEST['task'])) {
-    db_query("INSERT INTO {todolist_task} SET nid = %d, `order` = %d, task = '%s';", $_REQUEST['nid'], $_REQUEST['order'], $_REQUEST['task']);
-    $id = 'task-' . db_result(db_query("SELECT tid FROM {todolist_task} ORDER BY tid DESC LIMIT 1;"));
-    todolist_ok_js(); ?>
-TodoList.add_incomplete_list();
-$('.todolist.incomplete').append('<li class="task" id="<?php print $id ?>"><input type="checkbox" name="<?php print $id ?>" /><?php print _todolist_js_safe($_POST['task']) ?></li>');
-$('#<?php print $id ?>').each(TodoList.add_nub).each(TodoList.bind_task).Highlight(1000, '#ff0');
-$('.todolist.incomplete').SortableAddItem($('#<?php print $id ?>').get(0));
-    <?php exit;
-  } else todolist_bad_request();
-}
-
-/**
- * MENU_CALLBACK function for /todolist/toggle_task.
- */
-function todolist_toggle_task() {
-  if (isset($_REQUEST['id']) && isset($_REQUEST['order']) && isset($_REQUEST['checked'])) {
-    $completed = time();
-    db_query("UPDATE {todolist_task} SET status = %d, `order` = %d WHERE tid = %d LIMIT 1;", $_REQUEST['checked']? $completed : 0, $_REQUEST['order'], substr($_REQUEST['id'], 5));
-    todolist_ok_js();
-    if ($_REQUEST['checked'] && todolist_user_access('complete tasks')): ?>
-$('#<?php print $_REQUEST['id'] ?> input[@type=checkbox]').after('<a href="javascript:void(0)" title="Delete this task" class="delete" onclick="return TodoList.delete_task(\'<?php print $_REQUEST['id'] ?>\')">Delete</a> <span><?php print date('M d', $completed) ?></span> ');
-if (!$('.todolist.complete').length) $('<ul class="todolist complete"></ul>').insertAfter('#todolist-add-task-form');
-$('#<?php print $_REQUEST['id'] ?>').prependTo('.todolist.complete').each(TodoList.unbind_nub).Highlight(1000, '#ff0');
-    <?php elseif (todolist_user_access('uncomplete tasks')): ?>
-$('#<?php print $_REQUEST['id'] ?> > a.delete').remove();
-$('#<?php print $_REQUEST['id'] ?> span').remove();
-TodoList.add_incomplete_list();
-$('#<?php print $_REQUEST['id'] ?>').appendTo('.todolist.incomplete').each(TodoList.bind_nub).Highlight(1000, '#ff0');
-    <?php endif;
-    exit;
-  } else todolist_bad_request();
-}
-
-/**
- * MENU_CALLBACK function for /todolist/delete_task.
- */
-function todolist_delete_task() {
-  if (todolist_user_access('delete tasks'))
-  if (isset($_REQUEST['id'])) {
-    db_query("DELETE FROM {todolist_task} WHERE tid = %d LIMIT 1;", substr($_REQUEST['id'], 5));
-    todolist_ok_js(); ?>
-$('#<?php print $_REQUEST['id'] ?>').remove();
-    <?php exit;
-  } else todolist_bad_request();
-}
-
-/**
- * MENU_CALLBACK function for /todolist/reorder_task.
- */
-function todolist_reorder_task() {
-  if (todolist_user_access('reorder tasks'))
-  foreach($_REQUEST as $k => $tasks) {
-    if (substr($k, 0, 9) == 'todolist-') {
-      foreach($tasks as $order => $task) {
-        $sql .= 'WHEN '. substr($task, 5) .' THEN '. $order .' ';
-      }
-    }
-  }
-  if ($sql) {
-    db_query("UPDATE {todolist_task} SET `order` = CASE tid ". $sql ." END;");
-    todolist_ok_js();
-    exit;
-  } else todolist_bad_request();
-}
-
-/**
- * MENU_CALLBACK function for /todolist/edit_task.
- */
-function todolist_edit_task() {
-  if (isset($_REQUEST['tid']) && isset($_REQUEST['task'])) {
-    db_query("UPDATE {todolist_task} SET task = '%s' WHERE tid = %d LIMIT 1;", $_REQUEST['task'], $_REQUEST['tid']);
-    $task = db_fetch_object(db_query("SELECT tid, status, task FROM {todolist_task} WHERE tid = %d LIMIT 1;", $_REQUEST['tid']));
-    $field = theme('todolist_task', $task);
-    todolist_ok_js(); ?>
-$('#task-<?php print $_REQUEST['tid'] ?>').unbind('mouseover').unbind('mouseout').find('form').remove();
-$('#task-<?php print $_REQUEST['tid'] ?>').html('<?php print _todolist_js_safe($field['data']) ?>').each(TodoList.bind_nub).Highlight(1000, '#ff0');
-$('.todolist.incomplete').SortableAddItem($('#task-<?php print $_REQUEST['tid'] ?>').get(0));
-    <?php exit;
-  } else if (isset($_REQUEST['id'])) {
-    $task = db_fetch_object(db_query("SELECT tid, task FROM {todolist_task} WHERE tid = %d LIMIT 1;", substr($_REQUEST['id'], 5)));
-    $html = drupal_get_form('todolist_edit_task_form', $task);
-    todolist_ok_js(); ?>
-$('#<?php print $_REQUEST['id'] ?>').DraggableDestroy();
-$('#<?php print $_REQUEST['id'] ?>').unbind('mouseover').unbind('mouseout').text('').find('input').remove();
-$('#<?php print $_REQUEST['id'] ?>').append('<?php print _todolist_js_safe($html) ?>');
-$('#<?php print $_REQUEST['id'] ?> form').submit(TodoList.edit_task).find('textarea').focus();
-    <?php exit;
-  } else todolist_bad_request();
+<?php
+// $Id: todolist.module,v 1.5 2007/10/28 23:39:57 mikesmullin Exp $
+
+/**
+ * Implementation of hook_node_info().
+ */
+function todolist_node_info() {
+  return array(
+    'todolist' => array(
+      'name' => t('Todolist'),
+      'module' => 'todolist',
+      'description' => t('Create a new todolist.'),
+    )
+  );
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function todolist_perm() {
+  return array('create lists', 'create tasks', 'complete tasks', 'uncomplete tasks', 'reorder tasks', 'delete tasks', 'edit own tasks', 'edit tasks');
+}
+
+
+/**
+ * Implementation of hook_menu().
+ */
+function todolist_menu($may_cache) {
+  $items = array();
+
+  if ($may_cache) {
+  } else  {
+    $items[] = array(
+      'path' => 'node/add/todolist',
+      'title' => t('Todolist'),
+      'access' => user_access('create lists'),
+    );
+    $items[] = array(
+      'path' => 'todolist/create_task',
+      'callback' => 'todolist_create_task',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'todolist/edit_task',
+      'callback' => 'todolist_edit_task',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'todolist/toggle_task',
+      'callback' => 'todolist_toggle_task',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'todolist/reorder_task',
+      'callback' => 'todolist_reorder_task',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'todolist/delete_task',
+      'callback' => 'todolist_delete_task',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+  }
+
+  return $items;
+}
+
+/**
+ * Implementation of hook_form().
+ */
+function todolist_form(&$node) {
+
+  return array(
+    'title' => array(
+      '#type' => 'textfield',
+      '#title' => t('Title'),
+      '#required' => TRUE,
+      '#default_value' => $node->title,
+      '#weight' => -4,
+      '#access' => user_access('create lists'),
+    ),
+    'body' => array(
+      '#type' => 'textarea',
+      '#title' => t('Description'),
+      '#required' => FALSE,
+      '#default_value' => $node->body,
+      '#access' => user_access('create lists'),
+    ),
+  );
+
+}
+
+/**
+ * Add todolist JavaScript library to the current page.
+ */
+function todolist_add_js() {
+  static $done;
+  if (!isset($done)) {
+    drupal_add_js(drupal_get_path('module', 'todolist') . '/todolist.js');
+    $done = TRUE;
+  }
+}
+
+/**
+ * Add todolist JavaScript library to the current page.
+ */
+function todolist_add_css() {
+  static $done;
+  if (!isset($done)) {
+    drupal_add_js(drupal_get_path('module', 'todolist') . '/todolist.js');
+    $done = TRUE;
+  }
+}
+
+/**
+ * Implementation of hook_view().
+ */
+function todolist_view(&$node, $teaser = FALSE, $page = FALSE) {
+  if ($page) {
+    jquery_interface_add();
+    todolist_add_js();
+    drupal_add_css(drupal_get_path('module', 'todolist') . '/todolist.css', 'module');
+
+    $node->content['todolist'] = array('#value' => theme('todolist', $node));
+  }
+
+  return node_prepare($node, $teaser);
+}
+
+/**
+ * Generate a Todolist.
+ */
+function theme_todolist(&$node) {
+//	print "<pre>";
+//	print_r($node);
+//	print "</pre>";
+
+  $results = db_query("SELECT tid, status, task FROM {todolist_task} WHERE nid = %d ORDER BY status, `order`;", $node->nid);
+  while ($task = db_fetch_object($results)) {
+//print "<pre>";
+//print_r($task);
+//print "</pre>";
+  	$tasks[($task->status? 'complete' : 'incomplete')][] = theme('todolist_task', $task);
+  }
+  $output .= theme('todolist_item_list', $tasks['incomplete'], NULL, 'ul', array('id' => 'todolist-' . $node->nid, 'class' => 'todolist incomplete'));
+  $output .= drupal_get_form('todolist_add_task_form', $node);
+  $output .= theme('todolist_item_list', $tasks['complete'], NULL, 'ul', array('id' => 'todolist-complete-' . $node->nid,'class' => 'todolist complete'));
+
+  return $output;
+}
+/**
+ * Added by MFS - 
+ */
+function theme_todolist_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
+	$output = '<div class="item-list">';
+	if (isset($title)) {
+		$output .= '<h3>'. $title .'</h3>';
+	}
+
+
+	$output .= "<$type" . drupal_attributes($attributes) . '>';
+	if (!empty($items)) {
+		foreach ($items as $item) {
+			$attributes = array();
+			$children = array();
+			if (is_array($item)) {
+				foreach ($item as $key => $value) {
+					if ($key == 'data') {
+						$data = $value;
+					}
+					elseif ($key == 'children') {
+						$children = $value;
+					}
+					else {
+						$attributes[$key] = $value;
+					}
+				}
+			}
+			else {
+				$data = $item;
+			}
+			if (count($children) > 0) {
+				$data .= theme_item_list($children, NULL, $type, $attributes); // Render nested list
+			}
+			$output .= '<li' . drupal_attributes($attributes) . '>'. $data .'</li>';
+		}
+	}
+	$output .= "</$type>";
+
+	$output .= '</div>';
+	return $output;
+}
+
+/**
+ * Generate a Todolist Task.
+ */
+function theme_todolist_task(&$task) {
+  return array(
+    'data' => '<input type="checkbox" name="task-'. $task->tid .'"'. ($task->status? 'checked' : '') .' /> ' . ($task->status? '<a href="javascript:void(0)" title="Delete this task" class="delete" onclick="return TodoList.delete_task(\'task-'. $task->tid .'\')">Delete</a> <span>'. date('M d', $task->status) .'</span> ' : '') . $task->task,
+    'class' => 'task',
+    'id' => 'task-'. $task->tid,
+  );
+}
+
+/**
+ * Generate an Add Task form.
+ *
+ * @return Array $form
+ *   Forms API form array.
+ */
+function todolist_add_task_form(&$node) {
+  return array(
+    '#action' => url('todolist/create_task'),
+    array(
+      '#type' => 'fieldset',
+      '#title' => t('Add new task'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      'task' => array(
+        '#type' => 'textfield',
+        '#title' => t('Task'),
+        '#default_value' => '',
+        '#maxlength' => 255,
+        '#required' => TRUE,
+      ),
+      'submit' => array(
+        '#type' => 'submit',
+        '#value' => t('Add this task'),
+      ),
+      'nid' => array(
+        '#type' => 'hidden',
+        '#value' => $node->nid,
+      ),
+    ),
+  );
+}
+
+/**
+ * Generate an Edit Task form.
+ *
+ * @return Array $form
+ *   Forms API form array.
+ */
+function todolist_edit_task_form(&$task) {
+  return array(
+    '#action' => url('todolist/edit_task'),
+    array(
+      'task' => array(
+        '#type' => 'textarea',
+        '#default_value' => $task->task,
+        '#required' => TRUE,
+      ),
+      'submit' => array(
+        '#type' => 'submit',
+        '#value' => t('Save this task'),
+      ),
+      'tid' => array(
+        '#type' => 'hidden',
+        '#value' => $task->tid,
+      ),
+    ),
+  );
+}
+
+/**
+ * Check user_access and notify the browser of a forbidden request, if necessary.
+ *
+ * The server understood the request, but is refusing to fulfill it.
+ * Authorization will not help and the request SHOULD NOT be repeated.
+ *
+ * @param String $perm ...
+ *   The permission being checked for.
+ */
+function todolist_user_access() {
+  
+  if (user_access($perm)) { return TRUE; }
+
+  drupal_set_header('Status:403 Forbidden');
+  exit;
+}
+
+/**
+ * Notify the browser of a bad request.
+ *
+ * The request could not be understood by the server due to malformed syntax.
+ * The client SHOULD NOT repeat the request without modifications.
+ */
+function todolist_bad_request() {
+  drupal_set_header('Status:400 Bad Request');
+  exit;
+}
+
+/**
+ * Output JavaScript Content-Type headers.
+ */
+function todolist_ok_js() {
+  drupal_set_header('Status:200 OK');
+  drupal_set_header('Content-Type:text/javascript');
+}
+
+/**
+ * Escape single-quotes in a string.
+ *
+ * @param String $txt
+ *   A string to be used in JavaScript.
+ * @return String
+ *   An escaped string.
+ */
+function _todolist_js_safe($txt) {
+  $txt = str_replace("'", "\'", $txt);
+  $txt = preg_replace('/[\r\n]+/', '', $txt);
+  return $txt;
+}
+
+/**
+ * MENU_CALLBACK function for /todolist/create_task.
+ */
+function todolist_create_task() {
+  if (todolist_user_access('create tasks'))
+  if (isset($_REQUEST['nid']) && isset($_REQUEST['order']) && isset($_REQUEST['task'])) {
+    db_query("INSERT INTO {todolist_task} SET nid = %d, `order` = %d, task = '%s';", $_REQUEST['nid'], $_REQUEST['order'], $_REQUEST['task']);
+    $id = 'task-' . db_result(db_query("SELECT tid FROM {todolist_task} ORDER BY tid DESC LIMIT 1;"));
+    todolist_ok_js(); ?>
+TodoList.add_incomplete_list();
+$('#todolist-<?php print $_REQUEST['nid'] ?>.todolist.incomplete').append('<li class="task" id="<?php print $id ?>"><input type="checkbox" name="<?php print $id ?>" /><?php print _todolist_js_safe($_POST['task']) ?></li>');
+$('#<?php print $id ?>').each(TodoList.add_nub).each(TodoList.bind_task);
+$('.todolist.incomplete').SortableAddItem($('#<?php print $id ?>').get(0));
+    <?php exit;
+  } else todolist_bad_request();
+}
+
+/**
+ * MENU_CALLBACK function for /todolist/toggle_task.
+ */
+function todolist_toggle_task() {
+  if (isset($_REQUEST['id']) && isset($_REQUEST['order']) && isset($_REQUEST['checked'])) {
+    $completed = time();
+    db_query("UPDATE {todolist_task} SET status = %d, `order` = %d WHERE tid = %d LIMIT 1;", $_REQUEST['checked']? $completed : 0, $_REQUEST['order'], substr($_REQUEST['id'], 5));
+    $nid = db_result(db_query("SELECT nid FROM {todolist_task} WHERE tid = %d LIMIT 1;",substr($_REQUEST['id'], 5)));
+    todolist_ok_js();
+    if ($_REQUEST['checked'] && todolist_user_access('complete tasks')): ?>
+$('#<?php print $_REQUEST['id'] ?> input[@type=checkbox]').after('<a href="javascript:void(0)" title="Delete this task" class="delete" onclick="return TodoList.delete_task(\'<?php print $_REQUEST['id'] ?>\')">Delete</a> <span><?php print date('M d', $completed) ?></span> ');
+<?php /*//if (!$('#tasklist-<?php print $nid ?>.todolist.complete').length) $('<ul class="todolist complete"></ul>').insertAfter('#todolist-add-task-form');
+  if (!$('#tasklist-<?php print $nid ?>.todolist.complete').length) $('<ul class="todolist complete"></ul>').insertAfter($('#todolist-<?php print $nid ?>').parent('div.item-list').parent('div').children('form').get(0));
+*/?>
+$('#<?php print $_REQUEST['id'] ?>').prependTo('#todolist-complete-<?php print $nid ?>.todolist.complete').each(TodoList.unbind_nub);
+    <?php elseif (todolist_user_access('uncomplete tasks')): ?>
+$('#<?php print $_REQUEST['id'] ?> > a.delete').remove();
+$('#<?php print $_REQUEST['id'] ?> span').remove();
+TodoList.add_incomplete_list();
+$('#<?php print $_REQUEST['id'] ?>').appendTo('#todolist-<?php print $nid ?>.todolist.incomplete').each(TodoList.bind_nub);
+    <?php endif;
+    exit;
+  } else todolist_bad_request();
+}
+
+/**
+ * MENU_CALLBACK function for /todolist/delete_task.
+ */
+function todolist_delete_task() {
+  if (todolist_user_access('delete tasks'))
+  if (isset($_REQUEST['id'])) {
+    db_query("DELETE FROM {todolist_task} WHERE tid = %d LIMIT 1;", substr($_REQUEST['id'], 5));
+    todolist_ok_js(); ?>
+$('#<?php print $_REQUEST['id'] ?>').remove();
+    <?php exit;
+  } else todolist_bad_request();
+}
+
+/**
+ * MENU_CALLBACK function for /todolist/reorder_task.
+ */
+function todolist_reorder_task() {
+	$found = false;
+  if (todolist_user_access('reorder tasks')){
+  	foreach($_REQUEST as $k => $tasks) {
+  		if (substr($k, 0, 9) == 'todolist-') {
+  			$nid = substr($k,9);
+  			$sql = "";
+  			$sql2 = "";
+  			foreach($tasks as $order => $task) {
+  				$sql .= 'WHEN '. substr($task, 5) .' THEN '. $order .' ';
+  				if($sql2 != ""){
+  					$sql2 .= ",";
+  				}
+  				$sql2 .= substr($task, 5);
+  			}
+  			if($sql != ""){
+  				$found = true;
+  			   db_query("UPDATE {todolist_task} SET `order` = CASE tid ". $sql ." END;");
+  			   db_query("UPDATE {todolist_task} SET nid = " . $nid . " WHERE tid IN(" . $sql2 . ");");
+  			}
+  		}
+  		
+  	}
+  }
+  if ($found) {
+    //db_query("UPDATE {todolist_task} SET `order` = CASE tid ". $sql ." END;");
+    todolist_ok_js();
+    exit;
+  } else todolist_bad_request();
+}
+
+/**
+ * MENU_CALLBACK function for /todolist/edit_task.
+ */
+function todolist_edit_task() {
+  if (isset($_REQUEST['tid']) && isset($_REQUEST['task'])) {
+    db_query("UPDATE {todolist_task} SET task = '%s' WHERE tid = %d LIMIT 1;", $_REQUEST['task'], $_REQUEST['tid']);
+    $task = db_fetch_object(db_query("SELECT tid, status, task FROM {todolist_task} WHERE tid = %d LIMIT 1;", $_REQUEST['tid']));
+    $field = theme('todolist_task', $task);
+    $nid = db_result(db_query("SELECT nid FROM {todolist_task} WHERE tid = %d LIMIT 1;", $_REQUEST['tid']));
+    todolist_ok_js(); ?>
+$('#task-<?php print $_REQUEST['tid'] ?>').unbind('mouseover').unbind('mouseout').find('form').remove();
+$('#task-<?php print $_REQUEST['tid'] ?>').html('<?php print _todolist_js_safe($field['data']) ?>').each(TodoList.bind_nub);
+$('#task-<?php print $_REQUEST['tid'] ?>').each(TodoList.bind_task);
+$('#tasklist-<?php print $nid ?>.todolist.incomplete').SortableAddItem($('#task-<?php print $_REQUEST['tid'] ?>').get(0));
+    <?php exit;
+  } else if (isset($_REQUEST['id'])) {
+    $task = db_fetch_object(db_query("SELECT tid, task FROM {todolist_task} WHERE tid = %d LIMIT 1;", substr($_REQUEST['id'], 5)));
+    $html = drupal_get_form('todolist_edit_task_form', $task);
+    todolist_ok_js(); ?>
+$('#<?php print $_REQUEST['id'] ?>').DraggableDestroy();
+$('#<?php print $_REQUEST['id'] ?>').unbind('mouseover').unbind('mouseout').text('').find('input').remove();
+$('#<?php print $_REQUEST['id'] ?>').append('<?php print _todolist_js_safe($html) ?>');
+$('#<?php print $_REQUEST['id'] ?> form').submit(TodoList.edit_task).find('textarea').focus();
+    <?php exit;
+  } else todolist_bad_request();
 }
