}
/**
+ * Deletes all changes of a transaction.
+ *
+ * @param integer $transaction A transaction id.
+ */
+ function deleteHistory($transaction)
+ {
+ $transaction = (int)$transaction;
+
+ /* Deleting comments. */
+ $query = 'SELECT log_value FROM whups_logs WHERE log_type = ? AND transaction_id = ?';
+ $values = array('comment', $transaction);
+ Horde::logMessage(
+ sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"; values="%s"',
+ $query, implode(',', $values)), 'DEBUG');
+ $comments = $this->_db->getCol($query, 'log_value', $values);
+ if (is_a($comments, 'PEAR_Error')) {
+ Horde::logMessage($comments, 'ERR');
+ return $comments;
+ }
+
+ if ($comments) {
+ $query = sprintf('DELETE FROM whups_comments WHERE comment_id IN (%s)',
+ implode(',', $comments));
+ Horde::logMessage(
+ sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"', $query), 'DEBUG');
+ $result = $this->_write_db->query($query);
+ if (is_a($result, 'PEAR_Error')) {
+ Horde::logMessage($result, 'ERR');
+ return $result;
+ }
+ }
+
+ /* Deleting attachments. */
+ if (isset($GLOBALS['conf']['vfs']['type'])) {
+ $query = 'SELECT ticket_id, log_value FROM whups_logs WHERE log_type = ? AND transaction_id = ?';
+ $values = array('attachment', $transaction);
+ Horde::logMessage(
+ sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"; values="%s"',
+ $query, implode(',', $values)), 'DEBUG');
+ $attachments = $this->_db->query($query, $values);
+ if (is_a($attachments, 'PEAR_Error')) {
+ Horde::logMessage($attachments, 'ERR');
+ return $attachments;
+ }
+ require_once 'VFS.php';
+ $vfs = &VFS::singleton($GLOBALS['conf']['vfs']['type'],
+ Horde::getDriverConfig('vfs'));
+ if (is_a($vfs, 'PEAR_Error')) {
+ return $vfs;
+ }
+
+ while ($attachment = $attachments->fetchRow(DB_FETCHMODE_ASSOC)) {
+ $dir = WHUPS_VFS_ATTACH_PATH . '/' . $attachment['ticket_id'];
+ if ($vfs->exists($dir, $attachment['log_value'])) {
+ try {
+ $result = $vfs->deleteFile($dir, $attachment['log_value']);
+ } catch (VFS_Exception $e) {
+ return PEAR::raiseError($e->getMessage());
+ }
+ } else {
+ Horde::logMessage(sprintf(_("Attachment %s not found."),
+ $attachment['log_value']),
+ 'WARN');
+ }
+ }
+ }
+
+ $query = 'DELETE FROM whups_logs WHERE transaction_id = ?';
+ Horde::logMessage(
+ sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"; values="%s"',
+ $query, implode(',', $values)),
+ 'DEBUG');
+ $result = $this->_write_db->query($query, array($transaction));
+ if (is_a($result, 'PEAR_Error')) {
+ Horde::logMessage($result, 'ERR');
+ }
+ return $result;
+ }
+
+ /**
* Return a list of queues with open tickets, and the number of
* open tickets in each.
*
}
if (count($changes)) {
+ // Admins can delete entries.
+ $delete_link = '';
+ if (Whups::hasPermission($vars->get('queue'), 'queue', Horde_Perms::DELETE)) {
+ $delete_link = Horde::applicationUrl('ticket/delete_history.php')
+ ->add(array('transaction' => $transaction,
+ 'id' => $vars->get('ticket_id'),
+ 'url' => Horde::selfUrl(true, false, true)))
+ ->link(array('title' => _("Delete entry"), 'onclick' => 'return window.confirm(\'' . addslashes(_("Permanently delete entry?")) . '\');'))
+ . Horde::img('delete.png', _("Delete entry"))
+ . '</a>';
+ }
+
ob_start();
$class = $private ? 'pc' : 'c';
?>
<td width="20%" class="<?php echo $class ?>_l nowrap" valign="top"><?php echo strftime($prefs->getValue('date_format'), $vars->get('timestamp')) ?></td>
<td width="20%" class="<?php echo $class ?>_m" valign="top"><?php echo $vars->get('user_id') ? Whups::formatUser($vars->get('user_id'), false, true, true) : ' ' ?></td>
<td width="30%" class="<?php echo $class ?>_m" valign="top"><?php echo implode('<br />', $changes) ?></td>
- <td width="30%" class="<?php echo $class ?>_r rightAlign" valign="top"><?php if ($comment && !$private) echo $reply ?></td>
+ <td width="30%" class="<?php echo $class ?>_r rightAlign" valign="top"><?php if ($comment && !$private) echo $reply . ' '; echo $delete_link; ?></td>
</tr>
<?php if ($comment): ?>
<tr><td colspan="4" class="<?php echo $class ?>_b">
--- /dev/null
+<?php
+/**
+ * Deletes a history entry from the ticket.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+ */
+
+require_once dirname(__FILE__) . '/../lib/Application.php';
+Horde_Registry::appInit('whups');
+
+$ticket = Whups::getCurrentTicket();
+if (!Whups::hasPermission($ticket->get('queue'), 'queue', Horde_Perms::DELETE)) {
+ $notification->push(_("Permission Denied"), 'horde.error');
+ header('Location: ' . Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true));
+ exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$result = $whups_driver->deleteHistory($vars->get('transaction'));
+if (is_a($result, 'PEAR_Error')) {
+ $notification->push($result, 'horde.error');
+} else {
+ $notification->push(_("Entry deleted."), 'horde.success');
+}
+
+if ($url = Horde_Util::getFormData('url')) {
+ header('Location: ' . $url);
+} else {
+ header('Location: ' . Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true));
+}