1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class extends Horde_Form_Renderer
12: {
13: 14: 15: 16: 17:
18: protected $_tokens = array();
19:
20: public function begin($title)
21: {
22: $this->_sectionHeader($title);
23: echo '<div id="comments">';
24: }
25:
26: public function render($transaction, &$vars)
27: {
28: global $prefs, $conf, $registry;
29: static $canUpdate, = 0;
30:
31: if (!isset($canUpdate)) {
32: $canUpdate = $GLOBALS['registry']->getAuth() &&
33: Whups::hasPermission($vars->get('queue'), 'queue', 'update');
34: }
35:
36: $comment = '';
37: $private = false;
38: $changes = array();
39:
40: $changelist = $vars->get('changes');
41: if (!$changelist) {
42: return '';
43: }
44:
45: 46:
47: foreach ($changelist as $change) {
48: switch ($change['type']) {
49: case 'summary':
50: $changes[] = sprintf(
51: _("Summary ⇒ %s"), htmlspecialchars($change['value']));
52: break;
53:
54: case 'attachment':
55: $ticket = $vars->get('ticket_id');
56: try {
57: if ($file = Whups::getAttachments($ticket, $change['value'])) {
58: $changes[] = sprintf(
59: _("New Attachment: %s"),
60: Whups::attachmentUrl($ticket, $file, $vars->get('queue')));
61: } else {
62: $changes[] = sprintf(
63: _("New Attachment: %s"),
64: htmlspecialchars($change['value']));
65: }
66: } catch (Whups_Exception $e) {
67: $changes[] = sprintf(
68: _("New Attachment: %s"),
69: htmlspecialchars($change['value']));
70: }
71: break;
72:
73: case 'delete-attachment':
74: $changes[] = sprintf(
75: _("Deleted Attachment: %s"),
76: htmlspecialchars($change['value']));
77: break;
78:
79: case 'assign':
80: $changes[] = sprintf(
81: _("Assigned to %s"),
82: Whups::formatUser($change['value'], false, true, true));
83: break;
84:
85: case 'unassign':
86: $changes[] = sprintf(
87: _("Taken from %s"),
88: Whups::formatUser($change['value'], false, true, true));
89: break;
90:
91: case 'comment':
92: $comment = $change['comment'];
93: $private = !empty($change['private']);
94: if ($comment) {
95: $reply =
96: Horde::link(
97: Horde::url(
98: Horde_Util::addParameter(
99: $canUpdate ? 'ticket/update.php' : 'ticket/comment.php',
100: array('id' => $vars->get('ticket_id'),
101: 'transaction' => $transaction))))
102: . _("Reply to this comment") . '</a>';
103: }
104: break;
105:
106: case 'queue':
107: $changes[] = sprintf(
108: _("Queue ⇒ %s"), htmlspecialchars($change['label']));
109: break;
110:
111: case 'version':
112: $changes[] = sprintf(
113: _("Version ⇒ %s"), htmlspecialchars($change['label']));
114: break;
115:
116: case 'type':
117: $changes[] = sprintf(
118: _("Type ⇒ %s"), htmlspecialchars($change['label']));
119: break;
120:
121: case 'state':
122: $changes[] = sprintf(
123: _("State ⇒ %s"), htmlspecialchars($change['label']));
124: break;
125:
126: case 'priority':
127: $changes[] = sprintf(
128: _("Priority ⇒ %s"), htmlspecialchars($change['label']));
129: break;
130:
131: case 'attribute':
132: $changes[] = sprintf(
133: _("%s ⇒ %s"),
134: htmlspecialchars($change['label']),
135: htmlspecialchars($change['human']));
136: break;
137:
138: case 'due':
139: if ($change['label']) {
140: $changes[] = sprintf(
141: _("Due ⇒ %s"),
142: strftime($prefs->getValue('date_format'), $change['label']));
143: }
144: break;
145: }
146: }
147:
148: if ($comment) {
149: $flowed = new Horde_Text_Flowed($comment, 'UTF-8');
150: $flowed->setDelSp(true);
151: $comment = $flowed->toFlowed(false);
152: $comment = $GLOBALS['injector']
153: ->getInstance('Horde_Core_Factory_TextFilter')
154: ->filter(
155: $comment,
156: array('text2html', 'simplemarkup', 'highlightquotes'),
157: array(
158: array('parselevel' => Horde_Text_Filter_Text2html::MICRO),
159: array(),
160: array()));
161: if ($prefs->getValue('autolink_tickets') &&
162: $conf['prefs']['autolink_terms']) {
163:
164: $comment = preg_replace_callback(
165: '/<a.*?<\/a>/', array($this, '_writeTokens'), $comment);
166: $comment = preg_replace_callback(
167: '/(' . $conf['prefs']['autolink_terms'] . ')\s*#?(\d+)/i',
168: array($this, '_autolink'), $comment);
169: $comment = preg_replace_callback(
170: '/\0/', array($this, '_readTokens'), $comment);
171: }
172:
173: $comment_count++;
174: if ($private) {
175: $comment_label = Horde::img('locked.png')
176: . sprintf(_("Comment #%d (Private)"), $comment_count);
177: } else {
178: $comment_label = sprintf(_("Comment #%d"), $comment_count);
179: }
180: array_unshift($changes, '<a href="#c' . $comment_count . '" id="c'
181: . $comment_count . '">'
182: . $comment_label
183: . '</a>');
184: }
185:
186: if (count($changes)) {
187:
188: $delete_link = '';
189: if (Whups::hasPermission($vars->get('queue'), 'queue', Horde_Perms::DELETE)) {
190: $delete_link = Horde::url('ticket/delete_history.php')
191: ->add(array('transaction' => $transaction,
192: 'id' => $vars->get('ticket_id'),
193: 'url' => Whups::urlFor('ticket', $vars->get('ticket_id'), true)))
194: ->link(array('title' => _("Delete entry"), 'onclick' => 'return window.confirm(\'' . addslashes(_("Permanently delete entry?")) . '\');'))
195: . Horde::img('delete.png', _("Delete entry"))
196: . '</a>';
197: }
198:
199: Horde::startBuffer();
200: $class = $private ? 'pc' : 'c';
201: ?>
202: <div id="t<?php echo (int)$transaction ?>">
203: <table cellspacing="0" width="100%">
204: <tr>
205: <td width="20%" class="<?php echo $class ?>_l nowrap" valign="top"><?php echo strftime($prefs->getValue('date_format') . ' ' . $prefs->getValue('time_format'), $vars->get('timestamp')) ?></td>
206: <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>
207: <td width="30%" class="<?php echo $class ?>_m" valign="top"><?php echo implode('<br />', $changes) ?></td>
208: <td width="30%" class="<?php echo $class ?>_r rightAlign" valign="top"><?php if ($comment && !$private) echo $reply . ' '; echo $delete_link; ?></td>
209: </tr>
210: <?php if ($comment): ?>
211: <tr><td colspan="4" class="<?php echo $class ?>_b">
212: <div class="comment-body">
213: <?php echo $comment ?>
214: </div>
215: </td></tr>
216: <?php else: ?>
217: <tr><td colspan="4" class="c_b"> </td></tr>
218: <?php endif; ?>
219: </table>
220: </div>
221: <?php
222: $html = Horde::endBuffer();
223: return $html;
224: }
225:
226: return '';
227: }
228:
229: 230: 231: 232: 233: 234: 235:
236: protected function _writeTokens($matches)
237: {
238: $this->_tokens[] = $matches[0];
239: return chr(0);
240: }
241:
242: 243: 244: 245: 246: 247: 248:
249: protected function _readTokens($matches)
250: {
251: return array_shift($this->_tokens);
252: }
253:
254: protected function _autolink($matches)
255: {
256: $url = Whups::urlFor('ticket', $matches[2]);
257: $link = '<strong>' . Horde::link($url, 'View ' . $matches[0])
258: . $matches[0] . '</a></strong>';
259: $state = $GLOBALS['whups_driver']->getTicketState($matches[2]);
260: if ($state['state_category'] == 'resolved') {
261: $link = '<del>' . $link . '</del>';
262: }
263: return $link;
264: }
265:
266: public function end()
267: {
268: echo '</div>';
269: }
270:
271: }
272: