/**
  * Transfer task categories for specified tickets
  *
  * @param $ID original ticket ID
  * @param $newID new ticket ID
  **/
 function transferTicketTaskCategory($ID, $newID)
 {
     global $DB;
     $task = new TicketTask();
     $query = "SELECT *\n                FROM `glpi_tickettasks`\n                WHERE `tickets_id` = '{$ID}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             while ($data = $DB->fetch_assoc($result)) {
                 $input = array();
                 if ($data['taskcategories_id'] > 0) {
                     $categ = new TaskCategory();
                     if ($categ->getFromDB($data['taskcategories_id'])) {
                         $inputcat['entities_id'] = $this->to;
                         $inputcat['completename'] = $categ->fields['completename'];
                         $catid = $categ->findID($inputcat);
                         if ($catid < 0) {
                             $catid = $categ->import($inputcat);
                         }
                         $input['id'] = $data['id'];
                         $input['tickets_id'] = $ID;
                         $input['taskcategories_id'] = $catid;
                         $task->update($input);
                     }
                 }
             }
         }
     }
 }
 /**
  * Transfer task categories for specified tickets
  *
  * @since version 0.83
  *
  * @param $itemtype  itemtype : Problem / Ticket
  * @param $ID        original ticket ID
  * @param $newID     new ticket ID
  **/
 function transferTaskCategory($itemtype, $ID, $newID)
 {
     global $DB;
     switch ($itemtype) {
         case 'Ticket':
             $table = 'glpi_tickettasks';
             $field = 'tickets_id';
             $task = new TicketTask();
             break;
         case 'Problem':
             $table = 'glpi_problemtasks';
             $field = 'problems_id';
             $task = new ProblemTask();
             break;
     }
     $query = "SELECT *\n                FROM `{$table}`\n                WHERE `{$field}` = '{$ID}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             while ($data = $DB->fetch_assoc($result)) {
                 $input = array();
                 if ($data['taskcategories_id'] > 0) {
                     $categ = new TaskCategory();
                     if ($categ->getFromDB($data['taskcategories_id'])) {
                         $inputcat['entities_id'] = $this->to;
                         $inputcat['completename'] = addslashes($categ->fields['completename']);
                         $catid = $categ->findID($inputcat);
                         if ($catid < 0) {
                             $catid = $categ->import($inputcat);
                         }
                         $input['id'] = $data['id'];
                         $input[$field] = $ID;
                         $input['taskcategories_id'] = $catid;
                         $task->update($input);
                     }
                 }
             }
         }
     }
 }