1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: class Mnemo_Ajax_Imple_EditNote extends Horde_Core_Ajax_Imple
11: {
12: public function __construct($params)
13: {
14:
15: if (empty($params['rows'])) {
16: $params['rows'] = 2;
17: }
18: if (empty($params['cols'])) {
19: $params['cols'] = 20;
20: }
21: parent::__construct($params);
22: }
23:
24: public function attach()
25: {
26: Horde::addScriptFile('effects.js', 'horde');
27: Horde::addScriptFile('inplaceeditor.js', 'horde');
28:
29: $params = array('input' => 'value',
30: 'id' => $this->_params['id']);
31:
32: $url = $this->_getUrl('EditNote', 'mnemo', $params);
33: $loadTextUrl = $this->_getUrl('EditNote', 'mnemo', array_merge($params, array('action' => 'load')));
34: $js = array();
35:
36: $js[] =
37: "new InPlaceEditor('" . $this->_params['domid'] . "', '" . $url . "', {"
38: . " callback: function(form, value) {"
39: . " return 'value=' + encodeURIComponent(value);},"
40: . " loadTextURL: '". $loadTextUrl . "',"
41: . " rows: " . (int)$this->_params['rows'] . ", "
42: . " autoWidth: true,"
43: . " emptyText: '" . _("Click to add text...") . "',"
44: . " onComplete: function(ipe, opts) { ipe.checkEmpty() },"
45: . " cancelText: '" . _("Cancel") . "',"
46: . " okText: '" . _("Ok") . "',"
47: . " cancelClassName: ''"
48: . " });";
49:
50: Horde::addInlineScript($js, 'dom');
51: }
52:
53: public function handle($args, $post)
54: {
55: if ($GLOBALS['registry']->getAuth()) {
56:
57: if (!empty($args['action']) && $args['action'] == 'load') {
58: $id = $args['id'];
59: $storage = $GLOBALS['injector']->getInstance('Mnemo_Factory_Driver')->create();
60: $memo = $storage->getByUID($id);
61: return $memo['body'];
62: }
63: if (empty($args['input']) ||
64: is_null($pref_value = Horde_Util::getPost($args['input'], null)) ||
65: empty($args['id'])) {
66:
67: return '';
68: }
69:
70: $storage = $GLOBALS['injector']->getInstance('Mnemo_Factory_Driver')->create();
71: $memo = $storage->getByUID($args['id']);
72: $share = $GLOBALS['mnemo_shares']->getShare($memo['memolist_id']);
73: if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
74: throw new Horde_Exception_PermissionDenied(_("You do not have permission to edit this note."));
75: }
76:
77: $storage->modify($memo['memo_id'], $memo['desc'], $pref_value);
78: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter(
79: $pref_value,
80: 'text2html',
81: array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
82: }
83: }
84: }
85: