1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16:
17: if (!defined('MNEMO_BASE')) {
18: define('MNEMO_BASE', dirname(__FILE__) . '/..');
19: }
20:
21: if (!defined('HORDE_BASE')) {
22: 23:
24: if (file_exists(MNEMO_BASE . '/config/horde.local.php')) {
25: include MNEMO_BASE . '/config/horde.local.php';
26: } else {
27: define('HORDE_BASE', MNEMO_BASE . '/..');
28: }
29: }
30:
31: 32:
33: require_once HORDE_BASE . '/lib/core.php';
34:
35: class Mnemo_Application extends Horde_Registry_Application
36: {
37: 38:
39: public $version = 'H4 (3.0.8-git)';
40:
41: 42: 43: 44:
45: protected function _init()
46: {
47: Mnemo::initialize();
48: }
49:
50: 51:
52: public function perms()
53: {
54: return array(
55: 'max_notes' => array(
56: 'title' => _("Maximum Number of Notes"),
57: 'type' => 'int'
58: )
59: );
60: }
61:
62: 63:
64: public function ($menu)
65: {
66: global $conf, $injector;
67:
68: $menu->add(Horde::url('list.php'), _("_List Notes"), 'mnemo.png', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null);
69:
70: if (Mnemo::getDefaultNotepad(Horde_Perms::EDIT) &&
71: ($injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes') === true ||
72: $injector->getInstance('Horde_Core_Perms')->hasAppPermission('max_notes') > Mnemo::countMemos())) {
73: $menu->add(Horde::url(Horde_Util::addParameter('memo.php', 'actionID', 'add_memo')), _("_New Note"), 'add.png', null, null, null, Horde_Util::getFormData('memo') ? '__noselection' : null);
74: }
75:
76:
77: $menu->add(Horde::url('search.php'), _("_Search"), 'search.png');
78:
79:
80: if ($conf['menu']['import_export']) {
81: $menu->add(Horde::url('data.php'), _("_Import/Export"), 'data.png');
82: }
83: }
84:
85: 86:
87: public function hasPermission($permission, $allowed, $opts = array())
88: {
89: if (is_array($allowed)) {
90: switch ($permission) {
91: case 'max_notes':
92: $allowed = max($allowed);
93: break;
94: }
95: }
96: return $allowed;
97: }
98:
99: 100:
101: public function prefsGroup($ui)
102: {
103: foreach ($ui->getChangeablePrefs() as $val) {
104: switch ($val) {
105: case 'default_notepad':
106: $notepads = array();
107: foreach (Mnemo::listNotepads() as $key => $val) {
108: $notepads[htmlspecialchars($key)] = htmlspecialchars($val->get('name'));
109: }
110: $ui->override['default_notepad'] = $notepads;
111: break;
112: }
113: }
114: }
115:
116:
117:
118: 119:
120: public function (Horde_Tree_Base $tree, $parent = null,
121: array $params = array())
122: {
123: $add = Horde::url('memo.php')->add('actionID', 'add_memo');
124:
125: $tree->addNode(
126: $parent . '__new',
127: $parent,
128: _("New Note"),
129: 1,
130: false,
131: array(
132: 'icon' => Horde_Themes::img('add.png'),
133: 'url' => $add
134: )
135: );
136:
137: foreach (Mnemo::listNotepads() as $name => $notepad) {
138: $tree->addNode(
139: $parent . $name . '__new',
140: $parent . '__new',
141: sprintf(_("in %s"), $notepad->get('name')),
142: 2,
143: false,
144: array(
145: 'icon' => Horde_Themes::img('add.png'),
146: 'url' => $add->copy()->add('memolist', $name)
147: )
148: );
149: }
150:
151: $tree->addNode(
152: $parent . '__search',
153: $parent,
154: _("Search"),
155: 1,
156: false,
157: array(
158: 'icon' => Horde_Themes::img('search.png'),
159: 'url' => Horde::url('search.php')
160: )
161: );
162: }
163:
164: 165:
166: public function removeUserData($user)
167: {
168: $error = false;
169: $notepads = $GLOBALS['mnemo_shares']->listShares(
170: $user, array('attributes' => $user));
171: foreach ($notepads as $notepad => $share) {
172: $driver = $GLOBALS['injector']
173: ->getInstance('Mnemo_Factory_Driver')
174: ->create($notepad);
175: try {
176: $driver->deleteAll();
177: } catch (Mnemo_Exception $e) {
178: Horde::logMessage($e, 'NOTICE');
179: $error = true;
180: }
181:
182: try {
183: $GLOBALS['mnemo_shares']->removeShare($share);
184: } catch (Horde_Share_Exception $e) {
185: Horde::logMessage($e, 'NOTICE');
186: $error = true;
187: }
188: }
189:
190:
191: try {
192: $shares = $GLOBALS['mnemo_shares']->listShares($user);
193: foreach ($shares as $share) {
194: $share->removeUser($user);
195: }
196: } catch (Horde_Share_Exception $e) {
197: Horde::logMessage($e, 'NOTICE');
198: $error = true;
199: }
200:
201: if ($error) {
202: throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user));
203: }
204: }
205:
206: }
207: