1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Ansel_View_Results extends Ansel_View_Ansel
18: {
19: 20: 21: 22: 23:
24: protected $_search;
25:
26: 27: 28: 29: 30:
31: protected $_owner;
32:
33: 34: 35: 36: 37:
38: private $_page;
39:
40: 41: 42: 43: 44:
45: private $_perPage;
46:
47: 48: 49: 50: 51: 52: 53:
54: public function __construct()
55: {
56: global $prefs, $conf;
57:
58: $notification = $GLOBALS['injector']->getInstance('Horde_Notification');
59: $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
60:
61: $this->_owner = Horde_Util::getFormData('owner', '');
62:
63: $this->_search = new Ansel_Search_Tag($GLOBALS['injector']->getInstance('Ansel_Tagger'), null, $this->_owner);
64: $this->_page = Horde_Util::getFormData('page', 0);
65: $action = Horde_Util::getFormData('actionID', '');
66: $image_id = Horde_Util::getFormData('image');
67: $vars = Horde_Variables::getDefaultVariables();
68:
69:
70: $this->_perPage = min($prefs->getValue('tilesperpage'), $conf['thumbnail']['perpage']);
71:
72: switch ($action) {
73:
74: case 'delete':
75: if (is_array($image_id)) {
76: $images = array_keys($image_id);
77: } else {
78: $images = array($image_id);
79: }
80:
81: foreach ($images as $image) {
82: $img = $ansel_storage->getImage($image);
83: $gallery = $ansel_storage->getgallery($img->gallery);
84: if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
85: $notification->push(
86: sprintf(_("Access denied deleting photos from \"%s\"."), $image), 'horde.error');
87: } else {
88: try {
89: $gallery->removeImage($image);
90: $notification->push(_("Deleted the photo."), 'horde.success');
91: } catch (Ansel_Exception $e) {
92: $notification->push(
93: sprintf(_("There was a problem deleting photos: %s"), $e->getMessage()), 'horde.error');
94: }
95: }
96: }
97:
98: Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect();
99: exit;
100:
101: case 'move':
102: if (is_array($image_id)) {
103: $images = array_keys($image_id);
104: } else {
105: $images = array($image_id);
106: }
107:
108:
109:
110: $newGallery = Horde_Util::getFormData('new_gallery');
111: if ($images && $newGallery) {
112: try {
113: $newGallery = $ansel_storage->getGallery($newGallery);
114:
115: $galleries = array();
116: foreach ($images as $image) {
117: $img = $ansel_storage->getImage($image);
118: $galleries[$img->gallery][] = $image;
119: }
120: foreach ($galleries as $gallery_id => $images) {
121: $gallery = $ansel_storage->getGallery($gallery_id);
122: try {
123: $result = $gallery->moveImagesTo($images, $newGallery);
124: $notification->push(
125: sprintf(ngettext("Moved %d photo from \"%s\" to \"%s\"",
126: "Moved %d photos from \"%s\" to \"%s\"",
127: count($images)),
128: count($images), $gallery->get('name'),
129: $newGallery->get('name')),
130: 'horde.success');
131: } catch (Exception $e) {
132: $notification->push($e->getMessage(), 'horde.error');
133: }
134: }
135: } catch (Ansel_Exception $e) {
136: $notification->push(_("Bad input."), 'horde.error');
137: }
138: }
139:
140: Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect();
141: exit;
142:
143: case 'copy':
144: if (is_array($image_id)) {
145: $images = array_keys($image_id);
146: } else {
147: $images = array($image_id);
148: }
149:
150: $newGallery = Horde_Util::getFormData('new_gallery');
151: if ($images && $newGallery) {
152: try {
153:
154: $newGallery = $ansel_storage->getGallery($newGallery);
155: $galleries = array();
156: foreach ($images as $image) {
157: $img = $ansel_storage->getImage($image);
158: $galleries[$img->gallery][] = $image;
159: }
160: foreach ($galleries as $gallery_id => $images) {
161: $gallery = $ansel_storage->getGallery($gallery_id);
162: try {
163: $result = $gallery->copyImagesTo($images, $newGallery);
164: $notification->push(
165: sprintf(ngettext("Copied %d photo from %s to %s",
166: "Copied %d photos from %s to %s",
167: count($images)),
168: count($images), $gallery->get('name'),
169: $newGallery->get('name')),
170: 'horde.success');
171: } catch (Exception $e) {
172: $notification->push($e->getMessage(), 'horde.error');
173: }
174: }
175: } catch (Ansel_Exception $e) {
176: $notification->push(_("Bad input."), 'horde.error');
177: }
178: }
179: Ansel::getUrlFor('view', array('view' => 'Results'), true)->redirect();
180: exit;
181:
182:
183: case 'remove':
184: $tag = Horde_Util::getFormData('tag');
185: if (isset($tag)) {
186: $this->_search->removeTag($tag);
187: $this->_search->save();
188: }
189: break;
190:
191: case 'add':
192: default:
193: $tag = Horde_Util::getFormData('tag');
194: if (isset($tag)) {
195: $this->_search->addTag($tag);
196: $this->_search->save();
197: }
198: break;
199: }
200:
201:
202: if ($this->_search->tagCount() < 1) {
203: Horde::url('browse.php', true)->redirect();
204: exit;
205: }
206: }
207:
208: 209: 210: 211: 212:
213: public function getTitle()
214: {
215: return (!empty($this->_owner))
216: ? sprintf(_("Searching %s's photos tagged: "), $this->_owner)
217: : _("Searching all photos tagged: ");
218: }
219:
220: 221: 222: 223: 224:
225: public function html()
226: {
227: global $conf, $prefs;
228:
229:
230: $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
231:
232:
233: try {
234: $results = $this->_search->getSlice($this->_page, $this->_perPage);
235: } catch (Ansel_Exception $e) {
236: Horde::logMessage($e->getMessage(), 'ERR');
237: return _("An error has occured retrieving the image. Details have been logged.");
238: }
239: $total = $this->_search->count();
240: $total = $total['galleries'] + $total['images'];
241:
242:
243: $numimages = count($results);
244: $tilesperrow = $prefs->getValue('tilesperrow');
245:
246:
247: if ($conf['tags']['relatedtags']) {
248: $rtags = $this->_search->getRelatedTags();
249: $rtaghtml = '<ul>';
250:
251: $links = Ansel::getTagLinks($rtags, 'add');
252: foreach ($rtags as $id => $taginfo) {
253: if (!empty($this->_owner)) {
254: $links[$id]->add('owner', $this->_owner);
255: }
256: $rtaghtml .= '<li>' . $links[$id]->link(array('title' => sprintf(ngettext("%d photo", "%d photos",$taginfo['total']),$taginfo['total']))) . $taginfo['tag_name'] . '</a></li>';
257: }
258: $rtaghtml .= '</ul>';
259: }
260: $style = Ansel::getStyleDefinition($GLOBALS['prefs']->getValue('default_gallerystyle'));
261: $viewurl = Horde::url('view.php')->add(array('view' => 'Results',
262: 'actionID' => 'add'));
263:
264: $vars = Horde_Variables::getDefaultVariables();
265: $option_move = $option_copy = $ansel_storage->countGalleries($GLOBALS['registry']->getAuth(), array('perm' => Horde_Perms::EDIT));
266:
267: $this->_pagestart = ($this->_page * $this->_perPage) + 1;
268: $this->_pageend = min($this->_pagestart + $numimages - 1, $this->_pagestart + $this->_perPage - 1);
269: $this->_pager = new Horde_Core_Ui_Pager('page', $vars, array('num' => $total,
270: 'url' => $viewurl,
271: 'perpage' => $this->_perPage));
272: Horde::startBuffer();
273: include ANSEL_TEMPLATES . '/view/results.inc';
274: return Horde::endBuffer();
275: }
276:
277: public function viewType()
278: {
279: return 'Results';
280: }
281:
282: public function getGalleryCrumbData()
283: {
284: return array();
285: }
286:
287: }
288: