diff --git a/include/class.ticket.php b/include/class.ticket.php
index 727d0a82ed3c53de35a4a5deb017317aff9cb2a9..71f8dc76559e9198f9ee22c5d258815d957db848 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -778,6 +778,11 @@ class Ticket {
             case 'overdue':
                 return $this->markOverdue();
                 break;
+            case 'notdue':
+                return $this->clearOverdue();
+                break;
+            case 'unassined':
+                return $this->unassign();
         }
 
         return false;
@@ -1004,7 +1009,7 @@ class Ticket {
         $assigner = $thisstaff?$thisstaff:'SYSTEM (Auto Assignment)';
         
         //Log an internal note - no alerts on the internal note.
-        $this->postNote('Ticket Assigned to '.$assignee->getName(), $comments, $assigner, false);
+        $this->logNote('Ticket Assigned to '.$assignee->getName(), $comments, $assigner, false);
 
         //See if we need to send alerts
         if(!$alert || !$cfg->alertONAssignment()) return true; //No alerts!
@@ -1203,6 +1208,21 @@ class Ticket {
         return true;
     }
 
+    function clearOverdue() {
+
+        if(!$this->isOverdue()) 
+            return true;
+
+        $sql='UPDATE '.TICKET_TABLE.' SET isoverdue=0, updated=NOW() ';
+        //clear due date if it's in the past
+        if($this->getDueDate() && strtotime($this->getDueDate())<=time())
+            $sql.=', duedate=NULL';
+
+        $sql.=' WHERE ticket_id='.db_input($this->getId());
+
+        return (db_query($sql) && db_affected_rows());
+    }
+
     //Dept Tranfer...with alert.. done by staff 
     function transfer($deptId, $comments, $alert = true) {
         
@@ -1224,9 +1244,9 @@ class Ticket {
         $this->selectSLAId();
                   
         /*** log the transfer comments as internal note - with alerts disabled - ***/
-        $title='Dept. Transfer from '.$currentDept.' to '.$this->getDeptName();
+        $title='Ticket transfered from '.$currentDept.' to '.$this->getDeptName();
         $comments=$comments?$comments:$title; 
-        $this->postNote($title, $comments, $thisstaff, false);
+        $this->logNote($title, $comments, $thisstaff, false);
 
         $this->logEvent('transferred');
         
@@ -1318,7 +1338,7 @@ class Ticket {
         if($assignId[0]=='t') {
             $rv=$this->assignToTeam($id, $note, $alert);
         } elseif($assignId[0]=='s' || is_numeric($assignId)) {
-            $alert=($thisstaff && $thisstaff->getId()==$id)?false:$alert; //No alerts on self assigned tickets!!!
+            $alert=($alert && $thisstaff && $thisstaff->getId()==$id)?false:$alert; //No alerts on self assigned tickets!!!
             //We don't care if a team is already assigned to the ticket - staff assignment takes precedence
             $rv=$this->assignToStaff($id, $note, $alert);
         }
@@ -1436,7 +1456,7 @@ class Ticket {
     }
 
     /* public */ 
-    function postReply($vars, $errors, $alert = true) {
+    function postReply($vars, &$errors, $alert = true) {
         global $thisstaff, $cfg;
 
         if(!$vars['msgId'])
@@ -1522,7 +1542,7 @@ class Ticket {
         if(!$cfg || !$cfg->logTicketActivity())
             return 0;
 
-        return $this->postNote($title, $note, 'SYSTEM', false);
+        return $this->logNote($title, $note, 'SYSTEM', false);
     }
 
     // History log -- used for statistics generation (pretty reports)
@@ -1553,14 +1573,32 @@ class Ticket {
             && db_affected_rows() == 1;
     }
 
-    //Insert Internal Notes 
-    function postNote($title, $body, $poster, $alert=true) {        
-        global $cfg;
+    //Insert Internal Notes
+    function logNote($title, $note, $poster, $alert=true) {
+
+        return $this->postNote(
+                array('title' => $title, 'note' => $note),
+                $errors,
+                $poster,
+                $alert);
+    }
+
+    function postNote($vars, &$errors, $poster, $alert=true) {        
+        global $cfg, $thisstaff;
+
+        if(!$vars || !is_array($vars))
+            $errors['err'] = 'Missing or invalid data';
+        elseif(!$vars['note'])
+            $errors['note'] = 'Note required';
+
+        if($errors) return false;
 		
         $staffId = 0;
         if($poster && is_object($poster)) {
             $staffId = $poster->getId();
             $poster = $poster->getName();
+        } elseif(!$poster) {
+            $poster ='SYSTEM';
         }
 
         //TODO: move to class.thread.php
@@ -1568,19 +1606,30 @@ class Ticket {
         $sql= 'INSERT INTO '.TICKET_THREAD_TABLE.' SET created=NOW() '.
                 ',thread_type="N"'.
                 ',ticket_id='.db_input($this->getId()).
-                ',title='.db_input(Format::striptags($title)).
-                ',body='.db_input(Format::striptags($body)).
+                ',title='.db_input(Format::striptags($vars['title']?$vars['title']:'[No Title]')).
+                ',body='.db_input(Format::striptags($vars['note'])).
                 ',staff_id='.db_input($staffId).
                 ',poster='.db_input($poster);
         //echo $sql;
         if(!db_query($sql) || !($id=db_insert_id()))
             return false;
-
-        $note = Note::lookup($id, $this->getId());
+                
+        //Upload attachments IF ANY - TODO: validate attachment types??
+        if($_FILES['attachments'] && ($files=Format::files($_FILES['attachments'])))
+            $attachments = $this->uploadAttachments($files, $id, 'N');
+            
+        //Set state: Error on state change not critical! 
+        if(isset($vars['state']) && $vars['state']) {
+            if($this->setState($vars['state']))
+                $this->reload();
+        }
 
         // If alerts are not enabled then return a success.
         if(!$alert || !$cfg->alertONNewNote() || !($dept=$this->getDept()))
             return $id;
+
+        //Note obj.
+        $note = Note::lookup($id, $this->getId());
         
         if(!($tpl = $dept->getTemplate()))
             $tpl= $cfg->getDefaultTemplate();
@@ -1608,12 +1657,13 @@ class Ticket {
             if($cfg->alertDeptManagerONNewNote() && $dept && $dept->getManagerId())
                 $recipients[]=$dept->getManager();
 
+            $attachments =($attachments)?$this->getAttachments($id, 'N'):array();
             $sentlist=array();
             foreach( $recipients as $k=>$staff) {
                 if(!$staff || !is_object($staff) || !$staff->getEmail() || !$staff->isAvailable()) continue;
                 if(in_array($staff->getEmail(),$sentlist) || ($staffId && $staffId==$staff->getId())) continue; 
                 $alert = str_replace('%{recipient}',$staff->getFirstName(), $msg['body']);
-                $email->send($staff->getEmail(), $msg['subj'], $alert);
+                $email->send($staff->getEmail(), $msg['subj'], $alert, $attachments);
                 $sentlist[] = $staff->getEmail();
             }
         }
@@ -1649,7 +1699,7 @@ class Ticket {
                 else
                     $error ='Error #'.$file['error'];
 
-                $this->postNote('File Upload Error', $error, 'SYSTEM', false);
+                $this->logNote('File Upload Error', $error, 'SYSTEM', false);
                
                 $ost->logDebug('File Upload Error (Ticket #'.$this->getExtId().')', $error);
             }
@@ -1770,7 +1820,7 @@ class Ticket {
         if(!$vars['note'])
             $vars['note']=sprintf('Ticket Updated by %s', $thisstaff->getName());
 
-        $this->postNote('Ticket Updated', $vars['note'], $thisstaff);
+        $this->logNote('Ticket Updated', $vars['note'], $thisstaff);
         $this->reload();
         
         return true;
@@ -2170,7 +2220,7 @@ class Ticket {
         if($vars['assignId'] && $thisstaff->canAssignTickets()) { //Assign ticket to staff or team.
             $ticket->assign($vars['assignId'], $vars['note']);
         } elseif($vars['note']) { //Not assigned...save optional note if any
-            $ticket->postNote('New Ticket', $vars['note'], $thisstaff, false);
+            $ticket->logNote('New Ticket', $vars['note'], $thisstaff, false);
         } else { //Not assignment and no internal note - log activity
             $ticket->logActivity('New Ticket by Staff','Ticket created by staff -'.$thisstaff->getName());
         }