1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Kronolith_Ajax_Imple_TagActions extends Horde_Core_Ajax_Imple
12: {
13: 14:
15: public function attach()
16: {
17: Horde::addScriptFile('tagactions.js');
18: $dom_id = $this->_params['triggerId'];
19: $action = $this->_params['action'];
20: $content_id = $this->_params['resource'];
21: $content_type = $this->_params['type'];
22: $tag_id = !empty($this->_params['tagId']) ? $this->_params['tagId'] : null;
23: $endpoint = $this->_getUrl('TagActions', 'kronolith');
24:
25: if ($action == 'add') {
26: $js = "Event.observe('" . $dom_id . "_" . $content_id . "', 'click', function(event) {addTag('" . $content_id . "', '" . $content_type . "', '" . $endpoint . "'); Event.stop(event)});";
27: } elseif ($action == 'delete') {
28: $js = "Event.observe('" . $dom_id . "', 'click', function(event) {removeTag('" . $content_id . "', '" . $content_type . "', " . $tag_id . ", '" . $endpoint . "'); Event.stop(event)});";
29: }
30: Horde::addInlineScript($js, 'window');
31: }
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44: public function handle($args, $post)
45: {
46: $request = $args['action'];
47: $content = array('id' => $post['resource'], 'type' => $post['type']);
48: $tags = rawurldecode($post['tags']);
49:
50:
51:
52: $cal = $GLOBALS['kronolith_shares']->getShare($post['resource']);
53: $cal_owner = $cal->get('owner');
54: if($post['type'] == 'event') {
55: $event = Kronolith::getDriver()->getByUID($post['resource']);
56: $event_owner = $event->creator;
57: }
58:
59:
60:
61: $perm = empty($owner)
62: ? $GLOBALS['registry']->isAdmin()
63: : $owner == $GLOBALS['registry']->getAuth();
64:
65: if ($perm) {
66: $tagger = Kronolith::getTagger();
67: switch ($request) {
68: case 'add':
69: $tagger->tag($post['resource'], $tags, $cal_owner, $post['type']);
70: if (!empty($event_owner)) {
71: $tagger->tag($post['resource'], $tags, $event_owner, $post['type']);
72: }
73: break;
74: case 'remove':
75: $tagger->untag($post['resource'], (int)$tags, $post['type']);
76: break;
77: }
78: }
79: return $this->_getTagHtml($tagger, $post['resource'], $post['type']);
80:
81: }
82:
83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96:
97: private function _getTagHtml($tagger, $id, $type)
98: {
99: $tags = $tagger->getTags($id, 'calendar');
100: $js = '';
101: $html = '';
102:
103: if ($type == 'calendar') {
104: $cal = $GLOBALS['kronolith_shares']->getShare($id);
105: $hasEdit = $cal->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
106: } elseif ($type == 'event') {
107: $event = Kronolith::getDriver()->getByUID($id);
108: $hasEdit = $event->hasPermission(Horde_Perms::EDIT, $GLOBALS['registry']->getAuth());
109: }
110:
111: foreach ($tags as $tag_id => $tag) {
112: $html .= '<li class="panel-tags">' . htmlspecialchars($tag) . ($hasEdit ? '<a href="#" onclick="removeTag(\'' . $id . '\', \'' . $type . '\', ' . $tag_id . ',\'' . $this->_getUrl('TagActions', 'kronolith') . '\'); Event.stop(event);" id="remove' . md5($id . $tag_id) . '">' . Horde::img('delete-small.png', _("Remove Tag")) . '</a>' : '') . '</li>';
113: }
114:
115: return $html;
116: }
117:
118: }
119: