1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Jonah_View_StoryDelete extends Jonah_View_Base
15: {
16: public function run()
17: {
18: extract($this->_params, EXTR_REFS);
19:
20: $form_submit = $vars->get('submitbutton');
21: $channel_id = $vars->get('channel_id');
22: $story_id = $vars->get('id');
23:
24:
25: $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
26:
27: 28:
29: try {
30: $channel = $driver->getChannel($channel_id);
31: } catch (Exception $e) {
32: $notification->push(sprintf(_("Story editing failed: %s"), $e->getMessage()), 'horde.error');
33: Horde::url('channels/index.php', true)->redirect();
34: exit;
35: }
36:
37:
38: if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id)) {
39: $notification->push(_("You are not authorised for this action."), 'horde.warning');
40: $registry->authenticateFailure();
41: }
42:
43: try {
44: $story = $driver->getStory($channel_id, $story_id);
45: } catch (Exception $e) {
46: $notification->push(_("No valid story requested for deletion."), 'horde.message');
47: Horde::url('channels/index.php', true)->redirect();
48: exit;
49: }
50:
51:
52: if (empty($form_submit)) {
53: $vars = new Horde_Variables($story);
54: }
55:
56: $title = sprintf(_("Delete News Story \"%s\"?"), $vars->get('title'));
57:
58: $form = new Horde_Form($vars, $title);
59: $form->setButtons(array(_("Delete"), _("Do not delete")));
60: $form->addHidden('', 'channel_id', 'int', true, true);
61: $form->addHidden('', 'id', 'int', true, true);
62: $form->addVariable(_("Really delete this News Story?"), 'confirm', 'description', false);
63:
64: if ($form_submit == _("Delete")) {
65: if ($form->validate($vars)) {
66: $form->getInfo($vars, $info);
67: try {
68: $delete = $driver->deleteStory($info['channel_id'], $info['id']);
69: $notification->push(_("The story has been deleted."), 'horde.success');
70: Horde::url('stories/index.php', true)->add('channel_id', $channel_id)->setRaw(true)->redirect();
71: exit;
72: } catch (Exception $e) {
73: $notification->push(sprintf(_("There was an error deleting the story: %s"), $e->getMessage()), 'horde.error');
74: }
75: }
76: } elseif (!empty($form_submit)) {
77: $notification->push(_("Story has not been deleted."), 'horde.message');
78: $url = Horde::url('stories/index.php', true)->add('channel_id', $channel_id)->setRaw(true);
79: Horde::url('stories/index.php', true)->add('channel_id', $channel_id)->setRaw(true)->redirect();
80: exit;
81: }
82: require $registry->get('templates', 'horde') . '/common-header.inc';
83: require JONAH_TEMPLATES . '/menu.inc';
84: $form->renderActive(null, $vars, Horde::url('stories/delete.php'), 'post');
85: require $registry->get('templates', 'horde') . '/common-footer.inc';
86: }
87:
88: }