diff --git a/include/class.ticket.php b/include/class.ticket.php
index b0f54d2c761461ba987b0e4f91f86ad276d0290e..a6bff31c40f5ec4cc24f2434e72828ccde2407c3 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -653,10 +653,14 @@ class Ticket{
     //Set staff ID...assign/unassign/release (id can be 0)
     function setStaffId($staffId){
        
-      $sql='UPDATE '.TICKET_TABLE.' SET updated=NOW(), staff_id='.db_input($staffId)
-          .' WHERE ticket_id='.db_input($this->getId());
+        $sql='UPDATE '.TICKET_TABLE.' SET updated=NOW(), staff_id='.db_input($staffId)
+            .' WHERE ticket_id='.db_input($this->getId());
 
-      return (db_query($sql)  && db_affected_rows());
+        if (db_query($sql)  && db_affected_rows()) {
+            $this->staff_id = $staffId;
+            return true;
+        }
+        return false;
     }
 
     function setSLAId($slaId) {
@@ -768,7 +772,7 @@ class Ticket{
 
         $sql.=' WHERE ticket_id='.db_input($this->getId());
 
-        $this->track('closed');
+        $this->logEvent('closed');
         return (db_query($sql) && db_affected_rows());
     }
 
@@ -782,7 +786,7 @@ class Ticket{
 
         //TODO: log reopen event here 
 
-        $this->track('reopened');
+        $this->logEvent('reopened');
         return (db_query($sql) && db_affected_rows());
     }
 
@@ -1126,8 +1130,8 @@ class Ticket{
         if(!db_query($sql) || !db_affected_rows())
             return false;
 
+        $this->logEvent('overdue');
         $this->onOverdue($whine);
-        $this->track('overdue');
 
         return true;
     }
@@ -1148,6 +1152,7 @@ class Ticket{
              $this->reopen();
         
          $this->reload(); //reload - new dept!!
+         $this->logEvent('transferred');
 
          //Send out alerts if enabled AND requested
          if(!$alert || !$cfg->alertONTransfer() || !($dept=$this->getDept())) return true; //no alerts!!
@@ -1194,7 +1199,6 @@ class Ticket{
             }
          }
 
-         $this->track('transferred');
          return true;
     }
 
@@ -1207,8 +1211,8 @@ class Ticket{
             return false;
 
         $this->onAssign($note, $alert);
+        $this->logEvent('assigned');
 
-        $this->track('assigned');
         return true;
     }
 
@@ -1226,8 +1230,8 @@ class Ticket{
             $this->setStaffId(0);
 
         $this->onAssign($note, $alert);
+        $this->logEvent('assigned');
 
-        $this->track('assigned');
         return true;
     }
 
@@ -1432,7 +1436,7 @@ class Ticket{
     }
 
     // History log -- used for statistics generation (pretty reports)
-    function track($state, $staff=null) {
+    function logEvent($state, $staff=null) {
         global $thisstaff;
 
         if ($staff === null) {
@@ -1440,8 +1444,12 @@ class Ticket{
             else $staff='SYSTEM';               # XXX: Security Violation ?
         }
 
-        return db_query('INSERT INTO '.TICKET_HISTORY_TABLE
+        return db_query('INSERT INTO '.TICKET_EVENT_TABLE
             .' SET ticket_id='.db_input($this->getId())
+            .', staff_id='.db_input($this->getStaffId())
+            .', team_id='.db_input($this->getTeamId())
+            .', dept_id='.db_input($this->getDeptId())
+            .', topic_id='.db_input($this->getTopicId())
             .', timestamp=NOW(), state='.db_input($state)
             .', staff='.db_input($staff))
             && db_affected_rows() == 1;
@@ -1960,6 +1968,9 @@ class Ticket{
                     && ($client->getNumOpenTickets()==$cfg->getMaxOpenTickets())) {
             $ticket->onOpenLimit(($autorespond && strcasecmp($origin, 'staff')));
         }
+        
+        /* Start tracking ticket lifecycle events */
+        $ticket->logEvent('created');
 
         /* Phew! ... time for tea (KETEPA) */
 
diff --git a/main.inc.php b/main.inc.php
index bb997ebd6cb5d1d98d30136a66c55bd8a79008a7..7b10c018a69abb54ab321a917889e48fc80c99da 100644
--- a/main.inc.php
+++ b/main.inc.php
@@ -142,7 +142,7 @@
     define('TICKET_PRIORITY_TABLE',TABLE_PREFIX.'ticket_priority');
     define('PRIORITY_TABLE',TICKET_PRIORITY_TABLE);
     define('TICKET_LOCK_TABLE',TABLE_PREFIX.'ticket_lock');
-    define('TICKET_HISTORY_TABLE',TABLE_PREFIX.'ticket_history');
+    define('TICKET_EVENT_TABLE',TABLE_PREFIX.'ticket_event');
   
     define('EMAIL_TABLE',TABLE_PREFIX.'email');
     define('EMAIL_TEMPLATE_TABLE',TABLE_PREFIX.'email_template');
diff --git a/setup/inc/sql/osticket-v1.7-mysql.sql b/setup/inc/sql/osticket-v1.7-mysql.sql
index e6401d89f668d4c933b7dc0ab6e94b3642657bcd..7a31d814e1ad8544066830ad2d5d782aaf2da426 100644
--- a/setup/inc/sql/osticket-v1.7-mysql.sql
+++ b/setup/inc/sql/osticket-v1.7-mysql.sql
@@ -313,7 +313,7 @@ CREATE TABLE `%TABLE_PREFIX%email_template` (
 
 -- TODO: Dump revised copy before release!!!
 INSERT INTO `%TABLE_PREFIX%email_template` (`tpl_id`, `cfg_id`, `isactive`, `name`, `notes`, `ticket_autoresp_subj`, `ticket_autoresp_body`, `ticket_notice_subj`, `ticket_notice_body`, `ticket_alert_subj`, `ticket_alert_body`, `message_autoresp_subj`, `message_autoresp_body`, `message_alert_subj`, `message_alert_body`, `note_alert_subj`, `note_alert_body`, `assigned_alert_subj`, `assigned_alert_body`, `transfer_alert_subj`, `transfer_alert_body`, `ticket_overdue_subj`, `ticket_overdue_body`, `ticket_overlimit_subj`, `ticket_overlimit_body`, `ticket_reply_subj`, `ticket_reply_body`, `created`, `updated`) VALUES
-(1, 1, 1, 'osTicket Default Template', 'Default osTicket templates', 'Support Ticket Opened [#%ticket]', '%name,\r\n\r\nA request for support has been created and assigned ticket #%ticket. A representative will follow-up with you as soon as possible.\r\n\r\nYou can view this ticket''s progress online here: %url/view.php?e=%email&t=%ticket.\r\n\r\nIf you wish to send additional comments or information regarding this issue, please don''t open a new ticket. Simply login using the link above and update the ticket.\r\n\r\n%signature', '[#%ticket] %subject', '%name,\r\n\r\nOur customer care team has created a ticket, #%ticket on your behalf, with the following message.\r\n\r\n%message\r\n\r\nIf you wish to provide additional comments or information regarding this issue, please don''t open a new ticket. You can update or view this ticket''s progress online here: %url/view.php?e=%email&t=%ticket.\r\n\r\n%signature', 'New Ticket Alert', '%staff,\r\n\r\nNew ticket #%ticket created.\r\n-------------------\r\nName: %name\r\nEmail: %email\r\nDept: %dept\r\n\r\n%message\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', '[#%ticket] Message Added', '%name,\r\n\r\nYour reply to support request #%ticket has been noted.\r\n\r\nYou can view this support request progress online here: %url/view.php?e=%email&t=%ticket.\r\n\r\n%signature', 'New Message Alert', '%staff,\r\n\r\nNew message appended to ticket #%ticket\r\n\r\n----------------------\r\nName: %name\r\nEmail: %email\r\nDept: %dept\r\n\r\n%message\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'New Internal Note Alert', '%staff,\r\n\r\nInternal note appended to ticket #%ticket\r\n\r\n----------------------\r\nName: %name\r\n\r\n%note\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'Ticket #%ticket Assigned to you', '%assignee,\r\n\r\n%assigner has assigned ticket #%ticket to you or one of your teams!\r\n\r\n%note\r\n\r\nTo view complete details, simply login to the support system.\r\n\r\n%url/scp/tickets.php?id=%id\r\n\r\n- Your friendly Support Ticket System - powered by osTicket.', 'Ticket Transfer #%ticket - %dept', '%staff,\r\n\r\nTicket #%ticket has been transferred to %dept department\r\n\r\n----------------------\r\n\r\n%note\r\n\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%url/scp/ticket.php?id=%id\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'Stale Ticket Alert', '%staff,\r\n\r\nA ticket, #%ticket assigned to you or in your department is seriously overdue.\r\n\r\n%url/scp/tickets.php?id=%id\r\n\r\nWe should all work hard to guarantee that all tickets are being addressed in a timely manner. Enough baby talk...please address the issue or you will hear from me again.\r\n\r\n\r\n- Your friendly (although with limited patience) Support Ticket System - powered by osTicket.', 'Open Tickets Limit Reached', '%name\r\n\r\nYou've reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%url/view.php?e=%email\r\n\r\nThank you.\r\n\r\nSupport Ticket System', '[#%ticket] %subject', '%name,\r\n\r\nA customer support staff member has replied to your support request, #%ticket with the following response:\r\n\r\n%response\r\n\r\nWe hope this response has sufficiently answered your questions. If not, please do not send another email. Instead, reply to this email or login to your account for a complete archive of all your support requests and responses.\r\n\r\n%url/view.php?e=%email&t=%ticket\r\n\r\n%signature', '2011-08-05 17:00:03', '2012-03-19 01:44:54');
+(1, 1, 1, 'osTicket Default Template', 'Default osTicket templates', 'Support Ticket Opened [#%ticket]', '%name,\r\n\r\nA request for support has been created and assigned ticket #%ticket. A representative will follow-up with you as soon as possible.\r\n\r\nYou can view this ticket''s progress online here: %url/view.php?e=%email&t=%ticket.\r\n\r\nIf you wish to send additional comments or information regarding this issue, please don''t open a new ticket. Simply login using the link above and update the ticket.\r\n\r\n%signature', '[#%ticket] %subject', '%name,\r\n\r\nOur customer care team has created a ticket, #%ticket on your behalf, with the following message.\r\n\r\n%message\r\n\r\nIf you wish to provide additional comments or information regarding this issue, please don''t open a new ticket. You can update or view this ticket''s progress online here: %url/view.php?e=%email&t=%ticket.\r\n\r\n%signature', 'New Ticket Alert', '%staff,\r\n\r\nNew ticket #%ticket created.\r\n-------------------\r\nName: %name\r\nEmail: %email\r\nDept: %dept\r\n\r\n%message\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', '[#%ticket] Message Added', '%name,\r\n\r\nYour reply to support request #%ticket has been noted.\r\n\r\nYou can view this support request progress online here: %url/view.php?e=%email&t=%ticket.\r\n\r\n%signature', 'New Message Alert', '%staff,\r\n\r\nNew message appended to ticket #%ticket\r\n\r\n----------------------\r\nName: %name\r\nEmail: %email\r\nDept: %dept\r\n\r\n%message\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'New Internal Note Alert', '%staff,\r\n\r\nInternal note appended to ticket #%ticket\r\n\r\n----------------------\r\nName: %name\r\n\r\n%note\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'Ticket #%ticket Assigned to you', '%assignee,\r\n\r\n%assigner has assigned ticket #%ticket to you or one of your teams!\r\n\r\n%note\r\n\r\nTo view complete details, simply login to the support system.\r\n\r\n%url/scp/tickets.php?id=%id\r\n\r\n- Your friendly Support Ticket System - powered by osTicket.', 'Ticket Transfer #%ticket - %dept', '%staff,\r\n\r\nTicket #%ticket has been transferred to %dept department\r\n\r\n----------------------\r\n\r\n%note\r\n\r\n-------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%url/scp/ticket.php?id=%id\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'Stale Ticket Alert', '%staff,\r\n\r\nA ticket, #%ticket assigned to you or in your department is seriously overdue.\r\n\r\n%url/scp/tickets.php?id=%id\r\n\r\nWe should all work hard to guarantee that all tickets are being addressed in a timely manner. Enough baby talk...please address the issue or you will hear from me again.\r\n\r\n\r\n- Your friendly (although with limited patience) Support Ticket System - powered by osTicket.', 'Open Tickets Limit Reached', '%name\r\n\r\nYou have reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%url/view.php?e=%email\r\n\r\nThank you.\r\n\r\nSupport Ticket System', '[#%ticket] %subject', '%name,\r\n\r\nA customer support staff member has replied to your support request, #%ticket with the following response:\r\n\r\n%response\r\n\r\nWe hope this response has sufficiently answered your questions. If not, please do not send another email. Instead, reply to this email or login to your account for a complete archive of all your support requests and responses.\r\n\r\n%url/view.php?e=%email&t=%ticket\r\n\r\n%signature', '2011-08-05 17:00:03', '2012-03-19 01:44:54');
 
 DROP TABLE IF EXISTS `%TABLE_PREFIX%file`;
 CREATE TABLE `%TABLE_PREFIX%file` (
@@ -598,10 +598,14 @@ CREATE TABLE `%TABLE_PREFIX%ticket_lock` (
   KEY `staff_id` (`staff_id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
-DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_history`;
-CREATE TABLE `%TABLE_PREFIX%ticket_history` (
+DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_event`;
+CREATE TABLE `%TABLE_PREFIX%ticket_event` (
   `ticket_id` int(11) unsigned NOT NULL default '0',
-  `state` enum('opened','closed','assigned','transferred','overdue') NOT NULL,
+  `staff_id` int(11) unsigned NOT NULL,
+  `team_id` int(11) unsigned NOT NULL,
+  `dept_id` int(11) unsigned NOT NULL,
+  `topic_id` int(11) unsigned NOT NULL,
+  `state` enum('created','closed','reopened','assigned','transferred','overdue') NOT NULL,
   `staff` varchar(255) NOT NULL default 'SYSTEM',
   `timestamp` datetime NOT NULL,
   KEY `ticket_state` (`ticket_id`, `state`, `timestamp`),
diff --git a/setup/inc/sql/osticket-v1.7-mysql.sql.md5 b/setup/inc/sql/osticket-v1.7-mysql.sql.md5
new file mode 100644
index 0000000000000000000000000000000000000000..73090636d948f041c1a368ef416674c6269a309a
--- /dev/null
+++ b/setup/inc/sql/osticket-v1.7-mysql.sql.md5
@@ -0,0 +1 @@
+f8856d56e51c5cc3416389de78b54515
diff --git a/setup/inc/sql/patches/02decaa2-60fcbee1.patch.sql b/setup/inc/sql/patches/02decaa2-60fcbee1.patch.sql
new file mode 100644
index 0000000000000000000000000000000000000000..351bea5821c9fc9a84743f780e5b8f3752b2a8e6
--- /dev/null
+++ b/setup/inc/sql/patches/02decaa2-60fcbee1.patch.sql
@@ -0,0 +1,6 @@
+UPDATE `%TABLE_PREFIX%email_template`
+    SET `overlimit_body` = '%name\r\n\r\nYou have reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%url/view.php?e=%email\r\n\r\nThank you.\r\n\r\nSupport Ticket System'
+    WHERE `tpl_id` = 1 AND `cfg_id` = 1;
+
+UPDATE `%TABLE_PREFIX%config`
+    SET `schema_signature`='60fcbee1da3180d1b690187aa5006c88';
diff --git a/setup/inc/sql/patches/522e5b78-02decaa2.patch.sql b/setup/inc/sql/patches/522e5b78-02decaa2.patch.sql
new file mode 100644
index 0000000000000000000000000000000000000000..6dc1f3a8afdb8fe83f75a7f10e9852284432725e
--- /dev/null
+++ b/setup/inc/sql/patches/522e5b78-02decaa2.patch.sql
@@ -0,0 +1,7 @@
+UPDATE `%TABLE_PREFIX%sla`
+    SET `created` = NOW(),
+        `updated` = NOW()
+    WHERE `created` IS NULL;
+
+UPDATE `%TABLE_PREFIX%config`
+    SET `schema_signature`='02decaa20c10c9615558762018e25507';
diff --git a/setup/inc/sql/patches/60fcbee1-f8856d56.patch.sql b/setup/inc/sql/patches/60fcbee1-f8856d56.patch.sql
new file mode 100644
index 0000000000000000000000000000000000000000..dcdb1850237b475327cd2b74c0e7fc00d68a5e62
--- /dev/null
+++ b/setup/inc/sql/patches/60fcbee1-f8856d56.patch.sql
@@ -0,0 +1,10 @@
+ALTER TABLE `%TABLE_PREFIX%history`
+    ADD `staff_id` int(11) unsigned NOT NULL AFTER `ticket_id`,
+    ADD `team_id` int(11) unsigned NOT NULL AFTER `staff_id`,
+    ADD `dept_id` int(11) unsigned NOT NULL AFTER `team_id`,
+    ADD `topic_id` int(11) unsigned NOT NULL AFTER `dept_id`;
+
+RENAME TABLE `%TABLE_PREFIX%history` TO `%TABLE_PREFIX%event`;
+
+UPDATE `%TABLE_PREFIX%config`
+    SET `schema_signature`='f8856d56e51c5cc3416389de78b54515';
diff --git a/setup/inc/sql/patches/7be60a84-522e5b78.patch.sql b/setup/inc/sql/patches/7be60a84-522e5b78.patch.sql
new file mode 100644
index 0000000000000000000000000000000000000000..17ab3e07bd82c42df9b5cf7b2a73107afffbb499
--- /dev/null
+++ b/setup/inc/sql/patches/7be60a84-522e5b78.patch.sql
@@ -0,0 +1,6 @@
+UPDATE `%TABLE_PREFIX%email_template`
+    SET `ticket_overlimit_subj` = 'Open Tickets Limit Reached'
+    WHERE `tpl_id` = 1 AND `cfg_id` = 1;
+
+UPDATE `%TABLE_PREFIX%config`
+    SET `schema_signature`='522e5b783c2824c67222260ee22baa93';
diff --git a/setup/inc/sql/v1.6st-1.7-upgrade-mysql.sql b/setup/inc/sql/v1.6st-1.7-upgrade-mysql.sql
index efeb8de6f26eb4e4c4a5e10140147c5b1ebdd3c6..3a2acf2295170c9b6263b33f05d649c378ed5dbb 100644
--- a/setup/inc/sql/v1.6st-1.7-upgrade-mysql.sql
+++ b/setup/inc/sql/v1.6st-1.7-upgrade-mysql.sql
@@ -26,10 +26,14 @@ ALTER TABLE `%TABLE_PREFIX%ticket`
         'Web', 'Email', 'Phone', 'API', 'Other') NOT NULL DEFAULT 'Other';
 
 -- Add table for ticket history (statistics) tracking
-DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_history`;
-CREATE TABLE `%TABLE_PREFIX%ticket_history` (
+DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_event`;
+CREATE TABLE `%TABLE_PREFIX%ticket_event` (
   `ticket_id` int(11) unsigned NOT NULL default '0',
-  `state` enum('opened','closed','assigned','transferred','overdue') NOT NULL,
+  `staff_id` int(11) unsigned NOT NULL,
+  `team_id` int(11) unsigned NOT NULL,
+  `dept_id` int(11) unsigned NOT NULL,
+  `topic_id` int(11) unsigned NOT NULL,
+  `state` enum('created','closed','reopened','assigned','transferred','overdue') NOT NULL,
   `staff` varchar(255) NOT NULL default 'SYSTEM',
   `timestamp` datetime NOT NULL,
   KEY `ticket_state` (`ticket_id`, `state`, `timestamp`),