Overview

Packages

  • Jonah
  • None

Classes

  • Jonah
  • Jonah_Api
  • Jonah_Block_Latest
  • Jonah_Driver
  • Jonah_Driver_Sql
  • Jonah_Exception
  • Jonah_Factory_Driver
  • Jonah_Form_Feed
  • Jonah_Form_Story
  • Jonah_Test
  • Jonah_View_ChannelDelete
  • Jonah_View_ChannelEdit
  • Jonah_View_ChannelList
  • Jonah_View_StoryDelete
  • Jonah_View_StoryEdit
  • Jonah_View_StoryList
  • Jonah_View_StoryPdf
  • Jonah_View_StoryView
  • Jonah_View_TagSearchList
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Jonah_View_StoryDelete:: handle story deletion
 4:  *
 5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file LICENSE for license information (BSD). If you
 8:  * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
 9:  *
10:  * @author Chuck Hagenbuch <chuck@horde.org>
11:  * @author Marko Djukic <marko@oblo.com>
12:  * @package Jonah
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:         /* Driver */
25:         $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
26: 
27:         /* Fetch the channel details, needed for later and to check if valid
28:          * channel has been requested. */
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:         /* Check permissions. */
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:         /* If not yet submitted set up the form vars from the fetched story. */
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: }
API documentation generated by ApiGen