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_StoryEdit:: to add/edit stories.
 4:  *
 5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file LICENSE for license information (BSD). If you did not
 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:  * @TODO: This will be rewritten to NOT use Horde_Form since we want more
15:  *        control over the form and, especially, the RTE.
16:  */
17: class Jonah_View_StoryEdit extends Jonah_View_Base
18: {
19:     /**
20:      * $notification
21:      * $registry
22:      * $vars
23:      *
24:      */
25:     public function run()
26:     {
27:         extract($this->_params, EXTR_REFS);
28: 
29:         $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
30: 
31:         /* Set up the form variables. */
32:         $channel_id = $vars->get('channel_id');
33: 
34:         /* Fetch the channel details, needed for later and to check if valid
35:          * channel has been requested. */
36:         try {
37:             $channel = $driver->getChannel($channel_id);
38:         } catch (Exception $e) {
39:             $notification->push(sprintf(_("Story editing failed: %s"), $e->getMessage()), 'horde.error');
40:             Horde::url('channels/index.php', true)->redirect();
41:             exit;
42:         }
43: 
44:         /* Check permissions. */
45:         if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
46:             $notification->push(_("You are not authorised for this action."), 'horde.warning');
47:             $registry->authenticateFailure();
48:         }
49: 
50:         /* Check if a story is being edited. */
51:         $story_id = $vars->get('id');
52:         if ($story_id && !$vars->get('formname')) {
53:             $story = $driver->getStory($channel_id, $story_id);
54:             $story['tags'] = implode(',', array_values($story['tags']));
55:             $vars = new Horde_Variables($story);
56:         }
57: 
58:         /* Set up the form. */
59:         $form = new Jonah_Form_Story($vars);
60:         if ($form->validate($vars)) {
61:             $form->getInfo($vars, $info);
62:             $info['author'] = $registry->getAuth();
63:             try {
64:                 $result = $driver->saveStory($info);
65:                 $notification->push(sprintf(_("The story \"%s\" has been saved."), $info['title']), 'horde.success');
66:                 Horde::url('stories/index.php')->add('channel_id', $channel_id)->redirect();
67:                 exit;
68:             } catch (Exception $e) {
69:                 $notification->push(sprintf(_("There was an error saving the story: %s"), $e->getMessage()), 'horde.error');
70:             }
71:         }
72: 
73:         /* Needed javascript. */
74:         Horde::addScriptFile('open_calendar.js', 'horde');
75:         $title = $form->getTitle();
76:         require $registry->get('templates', 'horde') . '/common-header.inc';
77:         require JONAH_TEMPLATES . '/menu.inc';
78:         $form->renderActive($form->getRenderer(), $vars, Horde::url('stories/edit.php'), 'post');
79:         require $registry->get('templates', 'horde') . '/common-footer.inc';
80:     }
81: 
82: }
83: 
API documentation generated by ApiGen