1: <?php
 2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 
17: class Jonah_View_StoryEdit extends Jonah_View_Base
18: {
19:     20: 21: 22: 23: 24: 
25:     public function run()
26:     {
27:         extract($this->_params, EXTR_REFS);
28: 
29:         $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
30: 
31:         
32:         $channel_id = $vars->get('channel_id');
33: 
34:         35: 
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:         
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:         
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:         
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:         
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: