1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) STMicroelectronics, 2006. All Rights Reserved. |
4
|
|
|
* Copyright (c) Enalean, 2015. |
5
|
|
|
* |
6
|
|
|
* Originally written by Manuel Vacelet, 2006 |
7
|
|
|
* |
8
|
|
|
* This file is a part of Codendi. |
9
|
|
|
* |
10
|
|
|
* Codendi is free software; you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU General Public License as published by |
12
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
13
|
|
|
* (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* Codendi is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU General Public License |
21
|
|
|
* along with Codendi. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
*/ |
23
|
|
|
require_once('DocmanConstants.class.php'); |
24
|
|
|
require_once('common/mvc/Controler.class.php'); |
25
|
|
|
require_once('common/include/HTTPRequest.class.php'); |
26
|
|
|
require_once('common/user/UserManager.class.php'); |
27
|
|
|
|
28
|
|
|
require_once('view/Docman_View_GetShowViewVisitor.class.php'); |
29
|
|
|
require_once('view/Docman_View_GetFieldsVisitor.class.php'); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
require_once('Docman_Token.class.php'); |
33
|
|
|
//require_once('DocmanOneFolderIsWriteable.class.php'); |
34
|
|
|
|
35
|
|
|
require_once('common/include/Feedback.class.php'); |
36
|
|
|
|
37
|
|
|
require_once('Docman_NotificationsManager.class.php'); |
38
|
|
|
require_once('Docman_NotificationsManager_Add.class.php'); |
39
|
|
|
require_once('Docman_NotificationsManager_Delete.class.php'); |
40
|
|
|
require_once('Docman_NotificationsManager_Move.class.php'); |
41
|
|
|
require_once('Docman_NotificationsManager_Subscribers.class.php'); |
42
|
|
|
|
43
|
|
|
require_once('Docman_Log.class.php'); |
44
|
|
|
require_once('common/event/EventManager.class.php'); |
45
|
|
|
|
46
|
|
|
require_once('Docman_PermissionsManager.class.php'); |
47
|
|
|
|
48
|
|
|
require_once('Docman_ReportFactory.class.php'); |
49
|
|
|
require_once('Docman_MetadataFactory.class.php'); |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
class Docman_Controller extends Controler { |
53
|
|
|
// variables |
54
|
|
|
var $request; |
55
|
|
|
var $user; |
56
|
|
|
var $groupId; |
57
|
|
|
var $themePath; |
58
|
|
|
var $plugin; |
59
|
|
|
var $logger; |
60
|
|
|
var $feedback; |
61
|
|
|
var $user_can_admin; |
62
|
|
|
var $reportId; |
63
|
|
|
var $hierarchy; |
64
|
|
|
|
65
|
|
|
function Docman_Controller(&$plugin, $pluginPath, $themePath, &$request) { |
66
|
|
|
$this->request =& $request; |
67
|
|
|
$this->user = null; |
68
|
|
|
$this->groupId = null; |
69
|
|
|
$this->user_can_admin = null; |
70
|
|
|
$this->pluginPath = $pluginPath; |
71
|
|
|
$this->themePath = $themePath; |
72
|
|
|
$this->plugin = $plugin; |
73
|
|
|
$this->view = null; |
74
|
|
|
$this->reportId = null; |
75
|
|
|
$this->hierarchy = array(); |
76
|
|
|
$this->feedback = false; |
77
|
|
|
|
78
|
|
|
$this->feedback =& $GLOBALS['Response']->_feedback; |
79
|
|
|
|
80
|
|
|
$event_manager =& $this->_getEventManager(); |
81
|
|
|
|
82
|
|
|
// Events that will call the Docman Logger |
83
|
|
|
$logEvents = array ( |
84
|
|
|
'plugin_docman_event_add', |
85
|
|
|
'plugin_docman_event_edit', |
86
|
|
|
'plugin_docman_event_move', |
87
|
|
|
'plugin_docman_event_del', |
88
|
|
|
'plugin_docman_event_del_version', |
89
|
|
|
'plugin_docman_event_access', |
90
|
|
|
'plugin_docman_event_new_version', |
91
|
|
|
'plugin_docman_event_restore', |
92
|
|
|
'plugin_docman_event_restore_version', |
93
|
|
|
'plugin_docman_event_metadata_update', |
94
|
|
|
'plugin_docman_event_set_version_author', |
95
|
|
|
'plugin_docman_event_set_version_date', |
96
|
|
|
'plugin_docman_event_lock_add', |
97
|
|
|
'plugin_docman_event_lock_del', |
98
|
|
|
'plugin_docman_event_perms_change', |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->logger =& new Docman_Log(); |
102
|
|
|
foreach ($logEvents as $event) { |
103
|
|
|
$event_manager->addListener($event, $this->logger, 'log', true); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// Other events |
107
|
|
|
$this->notificationsManager =& new Docman_NotificationsManager($this->getProject(), get_server_url().$this->getDefaultUrl(), $this->feedback, $this->getMailBuilder()); |
108
|
|
|
$event_manager->addListener('plugin_docman_event_edit', $this->notificationsManager, 'somethingHappen', true); |
109
|
|
|
$event_manager->addListener('plugin_docman_event_new_version', $this->notificationsManager, 'somethingHappen', true); |
110
|
|
|
$event_manager->addListener('plugin_docman_event_metadata_update', $this->notificationsManager, 'somethingHappen', true); |
111
|
|
|
$event_manager->addListener('send_notifications', $this->notificationsManager, 'sendNotifications', true); |
112
|
|
|
$this->notificationsManager_Add =& new Docman_NotificationsManager_Add($this->getProject(), get_server_url().$this->getDefaultUrl(), $this->feedback, $this->getMailBuilder()); |
113
|
|
|
$event_manager->addListener('plugin_docman_event_add', $this->notificationsManager_Add, 'somethingHappen', true); |
114
|
|
|
$event_manager->addListener('send_notifications', $this->notificationsManager_Add, 'sendNotifications', true); |
115
|
|
|
$this->notificationsManager_Delete =& new Docman_NotificationsManager_Delete($this->getProject(), get_server_url().$this->getDefaultUrl(), $this->feedback, $this->getMailBuilder()); |
116
|
|
|
$event_manager->addListener('plugin_docman_event_del', $this->notificationsManager_Delete, 'somethingHappen', true); |
117
|
|
|
$event_manager->addListener('send_notifications', $this->notificationsManager_Delete, 'sendNotifications', true); |
118
|
|
|
$this->notificationsManager_Move =& new Docman_NotificationsManager_Move($this->getProject(), get_server_url().$this->getDefaultUrl(), $this->feedback, $this->getMailBuilder()); |
119
|
|
|
$event_manager->addListener('plugin_docman_event_move', $this->notificationsManager_Move, 'somethingHappen', true); |
120
|
|
|
$event_manager->addListener('send_notifications', $this->notificationsManager_Move, 'sendNotifications', true); |
121
|
|
|
$this->notificationsManager_Subscribers = new Docman_NotificationsManager_Subscribers($this->getProject(), get_server_url().$this->getDefaultUrl(), $this->feedback, $this->getMailBuilder()); |
122
|
|
|
$event_manager->addListener('plugin_docman_event_subcribers', $this->notificationsManager_Subscribers, 'somethingHappen', true); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Wrapper to i18n string call for docman. |
127
|
|
|
* static |
128
|
|
|
*/ |
129
|
|
|
function txt($key, $vars = array()) { |
130
|
|
|
return $GLOBALS['Language']->getText('plugin_docman', $key, $vars); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// Franlky, this is not at all the best place to do this. |
134
|
|
|
function installDocman($ugroupsMapping, $group_id = false) { |
135
|
|
|
$_gid = $group_id ? $group_id : (int) $this->request->get('group_id'); |
136
|
|
|
|
137
|
|
|
$item_factory =& $this->_getItemFactory(); |
138
|
|
|
$root =& $item_factory->getRoot($_gid); |
139
|
|
|
if ($root) { |
140
|
|
|
// Docman already install for this project. |
141
|
|
|
return false; |
142
|
|
|
} else { |
143
|
|
|
$pm = ProjectManager::instance(); |
144
|
|
|
$project = $pm->getProject($_gid); |
145
|
|
|
$tmplGroupId = (int) $project->getTemplate(); |
146
|
|
|
$this->_cloneDocman($tmplGroupId, $_gid, $ugroupsMapping); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
function _cloneDocman($srcGroupId, $dstGroupId, $ugroupsMapping) { |
151
|
|
|
$user = $this->getUser(); |
152
|
|
|
|
153
|
|
|
// Clone Docman permissions |
154
|
|
|
$dPm = $this->_getPermissionsManager(); |
155
|
|
|
if($ugroupsMapping === false) { |
156
|
|
|
$dPm->setDefaultDocmanPermissions($dstGroupId); |
157
|
|
|
} |
158
|
|
|
else { |
159
|
|
|
$dPm->cloneDocmanPermissions($srcGroupId, $dstGroupId); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
// Clone Metadata definitions |
163
|
|
|
$metadataMapping = array(); |
164
|
|
|
$mdFactory = new Docman_MetadataFactory($srcGroupId); |
165
|
|
|
$mdFactory->cloneMetadata($dstGroupId, $metadataMapping); |
166
|
|
|
|
167
|
|
|
// Clone Items, Item's permissions and metadata values |
168
|
|
|
$itemFactory = $this->_getItemFactory(); |
169
|
|
|
$dataRoot = $this->getProperty('docman_root'); |
170
|
|
|
$itemMapping = $itemFactory->cloneItems($srcGroupId, $dstGroupId, $user, $metadataMapping, $ugroupsMapping, $dataRoot); |
171
|
|
|
|
172
|
|
|
// Clone reports |
173
|
|
|
$reportFactory = new Docman_ReportFactory($srcGroupId); |
174
|
|
|
$reportFactory->copy($dstGroupId, $metadataMapping, $user, false, $itemMapping); |
175
|
|
|
|
176
|
|
|
//@todo: verify that key for title for root is copied instead of |
177
|
|
|
// string |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
function getLogger() { |
181
|
|
|
return $this->logger; |
182
|
|
|
} |
183
|
|
|
function logsDaily($params) { |
184
|
|
|
$this->logger->logsDaily($params); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
function _getEventManager() { |
188
|
|
|
return EventManager::instance(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Obtain instance of Docman_PermissionsManager |
193
|
|
|
* |
194
|
|
|
* @return Docman_PermissionsManager |
195
|
|
|
*/ |
196
|
|
|
private function _getPermissionsManager() { |
197
|
|
|
return Docman_PermissionsManager::instance($this->getGroupId()); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
function &getUser() { |
201
|
|
|
if($this->user === null) { |
202
|
|
|
$um =& UserManager::instance(); |
203
|
|
|
$this->user = $um->getCurrentUser(); |
204
|
|
|
} |
205
|
|
|
return $this->user; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/***************** PERMISSIONS ************************/ |
209
|
|
|
function userCanRead($item_id) { |
210
|
|
|
$dPm = $this->_getPermissionsManager(); |
211
|
|
|
$user =& $this->getUser(); |
212
|
|
|
return $dPm->userCanRead($user, $item_id); |
213
|
|
|
} |
214
|
|
|
function userCanWrite($item_id) { |
215
|
|
|
$dPm = $this->_getPermissionsManager(); |
216
|
|
|
$user =& $this->getUser(); |
217
|
|
|
return $dPm->userCanWrite($user, $item_id); |
218
|
|
|
} |
219
|
|
|
function userCanManage($item_id) { |
220
|
|
|
$dPm = $this->_getPermissionsManager(); |
221
|
|
|
$user =& $this->getUser(); |
222
|
|
|
return $dPm->userCanManage($user, $item_id); |
223
|
|
|
} |
224
|
|
|
function userCanAdmin() { |
225
|
|
|
$dPm = $this->_getPermissionsManager(); |
226
|
|
|
$user =& $this->getUser(); |
227
|
|
|
return $dPm->userCanAdmin($user); |
228
|
|
|
} |
229
|
|
|
/******************************************************/ |
230
|
|
|
|
231
|
|
|
function setRequest($request) { |
232
|
|
|
$this->request = $request; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
function getGroupId() { |
236
|
|
|
if($this->groupId === null) { |
237
|
|
|
$_gid = (int) $this->request->get('group_id'); |
238
|
|
|
if($_gid > 0) { |
239
|
|
|
$this->groupId = $_gid; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
return $this->groupId; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
function getDefaultUrl() { |
246
|
|
|
$_gid = $this->getGroupId(); |
247
|
|
|
return $this->pluginPath.'/?group_id='.$_gid; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
function getAdminUrl() { |
251
|
|
|
$_gid = $this->getGroupId(); |
252
|
|
|
return $this->pluginPath.'/admin/?group_id='.$_gid; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
function getThemePath() { |
256
|
|
|
return $this->themePath; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
function setReportId($id) { |
260
|
|
|
$this->reportId = $id; |
261
|
|
|
} |
262
|
|
|
function getReportId() { |
263
|
|
|
return $this->reportId; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
function _initReport($item) { |
267
|
|
|
$reportFactory = new Docman_ReportFactory($this->getGroupId()); |
268
|
|
|
|
269
|
|
|
if($this->reportId === null && $this->request->exist('report_id')) { |
270
|
|
|
$this->reportId = (int) $this->request->get('report_id'); |
271
|
|
|
} |
272
|
|
|
$report =& $reportFactory->get($this->reportId, $this->request, $item, $this->feedback); |
273
|
|
|
|
274
|
|
|
$this->_viewParams['filter'] =& $report; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
|
278
|
|
|
/*private*/ function _checkBrowserCompliance() { |
279
|
|
|
if($this->request_type == 'http' && $this->request->browserIsNetscape4()) { |
280
|
|
|
$this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docman', 'docman_browserns4')); |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
function getValueInArrays($key, $array1, $array2) { |
285
|
|
|
$value = null; |
286
|
|
|
if(isset($array1[$key])) { |
287
|
|
|
$value = $array1[$key]; |
288
|
|
|
} |
289
|
|
|
elseif(isset($array2[$key])) { |
290
|
|
|
$value = $array2[$key]; |
291
|
|
|
} |
292
|
|
|
return $value; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
function setMetadataValuesFromUserInput(&$item, $itemArray, $metadataArray) { |
296
|
|
|
$mdvFactory = new Docman_MetadataValueFactory($this->groupId); |
297
|
|
|
$mdFactory = new Docman_MetadataFactory($this->groupId); |
298
|
|
|
|
299
|
|
|
$mdIter =& $item->getMetadataIterator(); |
300
|
|
|
$mdIter->rewind(); |
301
|
|
|
while($mdIter->valid()) { |
302
|
|
|
$md =& $mdIter->current(); |
303
|
|
|
|
304
|
|
|
$value = $this->getValueInArrays($md->getLabel(), $itemArray, $metadataArray); |
305
|
|
|
if($value !== null) { |
306
|
|
|
$mdv = $mdvFactory->newMetadataValue($item->getId(), $md->getId(), $md->getType(), $value); |
307
|
|
|
$val = $mdv->getValue(); |
308
|
|
|
$mdvFactory->validateInput($md, $val); |
309
|
|
|
$md->setValue($val); |
310
|
|
|
// Take care to update hardcoded values too. |
311
|
|
|
if($mdFactory->isHardCodedMetadata($md->getLabel())) { |
312
|
|
|
$item->updateHardCodedMetadata($md); |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
$mdIter->next(); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
function createItemFromUserInput() { |
320
|
|
|
$new_item = null; |
321
|
|
|
if($this->request->exist('item')) { |
322
|
|
|
$item_factory =& $this->_getItemFactory(); |
323
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
324
|
|
|
|
325
|
|
|
$i = $this->request->get('item'); |
326
|
|
|
$new_item = $item_factory->getItemFromRow($i); |
327
|
|
|
$new_item->setGroupId($this->_viewParams['group_id']); |
328
|
|
|
// Build metadata list (from db) ... |
329
|
|
|
$mdFactory->appendItemMetadataList($new_item); |
330
|
|
|
// ... and set the value (from user input) |
331
|
|
|
$this->setMetadataValuesFromUserInput($new_item, |
332
|
|
|
$i, |
333
|
|
|
$this->request->get('metadata')); |
334
|
|
|
if ($i['item_type'] == PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE) { |
335
|
|
|
$tmp_path = tempnam($GLOBALS['tmp_dir'], 'embedded_file'); |
336
|
|
|
$f = fopen($tmp_path, 'w'); |
337
|
|
|
fwrite($f, $this->request->get('content')); |
338
|
|
|
fclose($f); |
339
|
|
|
$v = new Docman_Version(); |
340
|
|
|
$v->setPath($tmp_path); |
341
|
|
|
$new_item->setCurrentVersion($v); |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
return $new_item; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
function updateMetadataFromUserInput(&$item) { |
348
|
|
|
$this->setMetadataValuesFromUserInput($item, |
349
|
|
|
$this->request->get('item'), |
350
|
|
|
$this->request->get('metadata')); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
function updateItemFromUserInput(&$item) { |
354
|
|
|
if($this->request->exist('item')) { |
355
|
|
|
$i = $this->request->get('item'); |
356
|
|
|
$itemFactory =& $this->_getItemFactory(); |
357
|
|
|
switch($itemFactory->getItemTypeForItem($item)) { |
358
|
|
|
case PLUGIN_DOCMAN_ITEM_TYPE_WIKI: |
359
|
|
|
$item->setPagename($i['wiki_page']); |
360
|
|
|
break; |
361
|
|
|
case PLUGIN_DOCMAN_ITEM_TYPE_LINK: |
362
|
|
|
$item->setUrl($i['link_url']); |
363
|
|
|
break; |
364
|
|
|
} |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
function request() { |
369
|
|
|
if ($this->request->exist('action') |
370
|
|
|
&& ($this->request->get('action') == 'plugin_docman_approval_reviewer' |
371
|
|
|
|| $this->request->get('action') == 'plugin_docman_approval_requester' |
372
|
|
|
) |
373
|
|
|
) |
374
|
|
|
{ |
375
|
|
|
if ($this->request->get('hide')) { |
376
|
|
|
user_set_preference('hide_'. $this->request->get('action'), 1); |
377
|
|
|
} else { |
378
|
|
|
user_del_preference('hide_'. $this->request->get('action')); |
379
|
|
|
} |
380
|
|
|
exit; |
|
|
|
|
381
|
|
|
} |
382
|
|
|
if (!$this->request->exist('group_id')) { |
383
|
|
|
$this->feedback->log('error', 'Project is missing.'); |
384
|
|
|
$this->_setView('Error'); |
385
|
|
|
} else { |
386
|
|
|
$_groupId = (int) $this->request->get('group_id'); |
387
|
|
|
$pm = ProjectManager::instance(); |
388
|
|
|
$project = $pm->getProject($_groupId); |
389
|
|
|
if($project == false) { |
390
|
|
|
$this->feedback->log('error', 'Project is missing.'); |
391
|
|
|
$this->_setView('Error'); |
392
|
|
|
return; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
// Browser alert |
396
|
|
|
$this->_checkBrowserCompliance(); |
397
|
|
|
|
398
|
|
|
//token for redirection |
399
|
|
|
$tok =& new Docman_Token(); |
400
|
|
|
|
401
|
|
|
$this->_viewParams['docman'] =& $this; |
402
|
|
|
$this->_viewParams['user'] =& $this->getUser(); |
403
|
|
|
$this->_viewParams['token'] = $tok->getToken(); |
404
|
|
|
$this->_viewParams['default_url'] = $this->getDefaultUrl(); |
405
|
|
|
$this->_viewParams['theme_path'] = $this->getThemePath(); |
406
|
|
|
$this->_viewParams['group_id'] = (int) $this->request->get('group_id'); |
407
|
|
|
if($this->request->exist('version_number')) { |
408
|
|
|
$this->_viewParams['version_number'] = (int) $this->request->get('version_number'); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
if ($this->request->exist('section')) { |
412
|
|
|
$this->_viewParams['section'] = $this->request->get('section'); |
413
|
|
|
} else if ($this->request->get('action') == 'permissions') { |
414
|
|
|
$this->_viewParams['section'] = 'permissions'; |
415
|
|
|
} |
416
|
|
|
$view = $this->request->exist('action') ? $this->request->get('action') : 'show'; |
417
|
|
|
$this->_viewParams['action'] = $view; |
418
|
|
|
|
419
|
|
|
// Start is used by Table view (like LIMIT start,offset) |
420
|
|
|
if($this->request->exist('start')) { |
421
|
|
|
$this->_viewParams['start'] = (int) $this->request->get('start'); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
if($this->request->exist('pv')) { |
425
|
|
|
$this->_viewParams['pv'] = (int) $this->request->get('pv'); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
if($this->request->exist('report')) { |
429
|
|
|
$this->_viewParams['report'] = $this->request->get('report'); |
430
|
|
|
$views = Docman_View_Browse::getDefaultViews(); |
431
|
|
|
$validator = new Valid_WhiteList('report', $views); |
432
|
|
|
$views_keys = array_keys($views); |
433
|
|
|
$default_view = $views[$views_keys[0]]; |
434
|
|
|
$this->_viewParams['report'] = $this->request->getValidated('report', $validator, $default_view); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
$item_factory =& $this->_getItemFactory(); |
438
|
|
|
$root =& $item_factory->getRoot($this->request->get('group_id')); |
439
|
|
|
if (!$root) { |
440
|
|
|
// Install |
441
|
|
|
$_gid = (int) $this->request->get('group_id'); |
442
|
|
|
|
443
|
|
|
$pm = ProjectManager::instance(); |
444
|
|
|
$project = $pm->getProject($_gid); |
445
|
|
|
$tmplGroupId = (int) $project->getTemplate(); |
446
|
|
|
$this->_cloneDocman($tmplGroupId, $_gid, false); |
447
|
|
|
if (!$item_factory->getRoot($_gid)) { |
448
|
|
|
$item_factory->createRoot($_gid, 'roottitle_lbl_key'); |
449
|
|
|
} |
450
|
|
|
$this->_viewParams['redirect_to'] = $_SERVER['REQUEST_URI']; |
451
|
|
|
$this->view = 'Redirect'; |
452
|
|
|
} else { |
453
|
|
|
$id = $this->request->get('id'); |
454
|
|
|
if (!$id && $this->request->exist('item')) { |
455
|
|
|
$i = $this->request->get('item'); |
456
|
|
|
if (isset($i['id'])) { |
457
|
|
|
$id = $i['id']; |
458
|
|
|
} |
459
|
|
|
} |
460
|
|
|
if ($id) { |
461
|
|
|
$item =& $item_factory->getItemFromDb($id); |
462
|
|
|
|
463
|
|
|
if (!$item) { |
464
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_item_deleted')); |
465
|
|
|
$this->_setView('DocmanError'); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
} else { |
469
|
|
|
$item =& $root; |
470
|
|
|
} |
471
|
|
|
if ($item) { |
472
|
|
|
// Load report |
473
|
|
|
// If the item (folder) defined in the report is not the |
474
|
|
|
// same than the current one, replace it. |
475
|
|
|
$this->_initReport($item); |
476
|
|
|
if($this->_viewParams['filter'] !== null |
477
|
|
|
&& $this->_viewParams['filter']->getItemId() !== null |
478
|
|
|
&& $this->_viewParams['filter']->getItemId() != $item->getId()) { |
479
|
|
|
$reportItem = $item_factory->getItemFromDb($this->_viewParams['filter']->getItemId()); |
480
|
|
|
// If item defined in the report exists, use it |
481
|
|
|
// otherwise raise an error |
482
|
|
|
if(!$reportItem) { |
483
|
|
|
$this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docman', 'error_report_baditemid')); |
484
|
|
|
} else { |
485
|
|
|
unset($item); |
486
|
|
|
$item = $reportItem; |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
if ($this->request->get('action') == 'ajax_reference_tooltip') { |
491
|
|
|
$this->groupId = $item->getGroupId(); |
492
|
|
|
} |
493
|
|
|
if ($item->getGroupId() != $this->getGroupId()) { |
494
|
|
|
$pm = ProjectManager::instance(); |
495
|
|
|
$g = $pm->getProject($this->getGroupId()); |
496
|
|
|
$this->_set_doesnot_belong_to_project_error($item, $g); |
497
|
|
|
} else { |
498
|
|
|
$user = $this->getUser(); |
499
|
|
|
$dpm = $this->_getPermissionsManager(); |
500
|
|
|
$can_read = $dpm->userCanAccess($user, $item->getId()); |
501
|
|
|
$folder_or_document = is_a($item, 'Docman_Folder') ? 'folder' : 'document'; |
502
|
|
|
if (!$can_read) { |
503
|
|
|
if ($this->request->get('action') == 'ajax_reference_tooltip') { |
504
|
|
|
$this->_setView('AjaxReferenceTooltipError'); |
505
|
|
|
} else { |
506
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_view')); |
507
|
|
|
$this->_setView('PermissionDeniedError'); |
508
|
|
|
} |
509
|
|
|
} else { |
510
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
511
|
|
|
$mdFactory->appendItemMetadataList($item); |
512
|
|
|
|
513
|
|
|
$get_show_view =& new Docman_View_GetShowViewVisitor(); |
514
|
|
|
$this->_viewParams['item'] =& $item; |
515
|
|
|
if (strpos($view, 'admin') === 0 && !$this->userCanAdmin()) { |
516
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_admin')); |
517
|
|
|
$this->view = $item->accept($get_show_view, $this->request->get('report')); |
518
|
|
|
} else { |
519
|
|
|
if($item->isObsolete()) { |
520
|
|
|
$this->feedback->log('warning', $this->txt('warning_obsolete')); |
521
|
|
|
} |
522
|
|
|
$this->_dispatch($view, $item, $root, $get_show_view); |
523
|
|
|
} |
524
|
|
|
} |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
} |
528
|
|
|
} |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
function _dispatch($view, $item, $root, $get_show_view) { |
532
|
|
|
$item_factory =& $this->_getItemFactory(); |
533
|
|
|
$user =& $this->getUser(); |
534
|
|
|
$dpm = $this->_getPermissionsManager(); |
535
|
|
|
|
536
|
|
|
switch ($view) { |
537
|
|
|
case 'show': |
538
|
|
|
if($item->isObsolete()) { |
539
|
|
|
if(!$this->userCanAdmin($item->getId())) { |
540
|
|
|
// redirect to details view |
541
|
|
|
$this->view = 'Details'; |
542
|
|
|
break; |
543
|
|
|
} |
544
|
|
|
} |
545
|
|
|
$this->view = $item->accept($get_show_view, $this->request->get('report')); |
546
|
|
|
break; |
547
|
|
|
case 'expandFolder': |
548
|
|
|
$this->action = 'expandFolder'; |
549
|
|
|
if ($this->request->get('view') == 'ulsubfolder') { |
550
|
|
|
$this->view = 'RawTree'; |
551
|
|
|
} else { |
552
|
|
|
$this->_viewParams['item'] =& $root; |
553
|
|
|
$this->view = 'Tree'; |
554
|
|
|
} |
555
|
|
|
break; |
556
|
|
|
case 'getRootFolder': |
557
|
|
|
$this->_viewParams['action_result'] = $root->getId(); |
558
|
|
|
$this->_setView('getRootFolder'); |
559
|
|
|
break; |
560
|
|
|
case 'collapseFolder': |
561
|
|
|
$this->action = 'collapseFolder'; |
562
|
|
|
$this->_viewParams['item'] =& $root; |
563
|
|
|
$this->view = 'Tree'; |
564
|
|
|
break; |
565
|
|
|
case 'admin_set_permissions': |
566
|
|
|
$this->action = $view; |
567
|
|
|
$this->view = 'Admin_Permissions'; |
568
|
|
|
break; |
569
|
|
|
case 'admin_change_view': |
570
|
|
|
$this->action = $view; |
571
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_view', |
572
|
|
|
'id' => $item->getParentId()); |
573
|
|
|
$this->view = 'RedirectAfterCrud'; |
574
|
|
|
break; |
575
|
|
|
case 'admin': |
576
|
|
|
case 'details': |
577
|
|
|
$this->view = ucfirst($view); |
578
|
|
|
break; |
579
|
|
|
case 'admin_view': |
580
|
|
|
$this->view = 'Admin_View'; |
581
|
|
|
break; |
582
|
|
|
case 'admin_permissions': |
583
|
|
|
$this->view = 'Admin_Permissions'; |
584
|
|
|
break; |
585
|
|
|
case 'admin_metadata': |
586
|
|
|
$this->view = 'Admin_Metadata'; |
587
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
588
|
|
|
$mdIter =& $mdFactory->getMetadataForGroup(); |
589
|
|
|
$this->_viewParams['mdIter'] =& $mdIter; |
590
|
|
|
break; |
591
|
|
|
case 'admin_md_details': |
592
|
|
|
// Sanitize |
593
|
|
|
$_mdLabel = $this->request->get('md'); |
594
|
|
|
|
595
|
|
|
$md = null; |
596
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
597
|
|
|
$valid = $this->validateMetadata($_mdLabel, $md); |
598
|
|
|
|
599
|
|
|
if(!$valid) { |
600
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', |
601
|
|
|
'error_invalid_md')); |
602
|
|
|
$this->view = 'RedirectAfterCrud'; |
603
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
604
|
|
|
} |
605
|
|
|
else { |
606
|
|
|
$this->view = 'Admin_MetadataDetails'; |
607
|
|
|
$mdFactory->appendMetadataValueList($md, false); |
608
|
|
|
$this->_viewParams['md'] =& $md; |
609
|
|
|
} |
610
|
|
|
break; |
611
|
|
|
case 'admin_md_details_update': |
612
|
|
|
$_name = trim($this->request->get('name')); |
613
|
|
|
$_label = $this->request->get('label'); |
614
|
|
|
|
615
|
|
|
$mdFactory = $this->_getMetadataFactory($this->_viewParams['group_id']); |
616
|
|
|
if($mdFactory->isValidLabel($_label)) { |
617
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_md_details', 'md' => $_label); |
618
|
|
|
if ($mdFactory->isHardCodedMetadata($_label) || $this->validateUpdateMetadata($_name, $_label)) { |
619
|
|
|
$this->action = $view; |
620
|
|
|
} |
621
|
|
|
} else { |
622
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
623
|
|
|
} |
624
|
|
|
$this->view = 'RedirectAfterCrud'; |
625
|
|
|
break; |
626
|
|
|
case 'admin_create_metadata': |
627
|
|
|
$_name = trim($this->request->get('name')); |
628
|
|
|
$valid = $this->validateNewMetadata($_name); |
629
|
|
|
|
630
|
|
|
if ($valid) { |
631
|
|
|
$this->action = $view; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
635
|
|
|
$this->view = 'RedirectAfterCrud'; |
636
|
|
|
break; |
637
|
|
|
case 'admin_delete_metadata': |
638
|
|
|
$valid = false; |
639
|
|
|
// md |
640
|
|
|
// Sanitize |
641
|
|
|
$_mdLabel = $this->request->get('md'); |
642
|
|
|
|
643
|
|
|
// Valid |
644
|
|
|
$logmsg = ''; |
645
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
646
|
|
|
$md = null; |
647
|
|
|
$vld = $this->validateMetadata($_mdLabel, $md); |
648
|
|
|
if($vld) { |
649
|
|
|
if(!$mdFactory->isHardCodedMetadata($md->getLabel())) { |
650
|
|
|
$valid = true; |
651
|
|
|
} |
652
|
|
|
else { |
653
|
|
|
$logmsg = $GLOBALS['Language']->getText('plugin_docman', |
654
|
|
|
'error_cannot_delete_hc_md'); |
655
|
|
|
} |
656
|
|
|
} |
657
|
|
|
else { |
658
|
|
|
$logmsg = $GLOBALS['Language']->getText('plugin_docman', |
659
|
|
|
'error_invalid_md'); |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
if(!$valid) { |
663
|
|
|
if($logmsg != '') { |
664
|
|
|
$this->feedback->log('error', $logmsg); |
665
|
|
|
} |
666
|
|
|
$this->view = 'RedirectAfterCrud'; |
667
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
668
|
|
|
} |
669
|
|
|
else { |
670
|
|
|
$this->action = $view; |
671
|
|
|
$this->_actionParams['md'] = $md; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
break; |
675
|
|
|
case 'admin_create_love': |
676
|
|
|
$mdFactory = $this->_getMetadataFactory($this->_viewParams['group_id']); |
677
|
|
|
if($mdFactory->isValidLabel($this->request->get('md'))) { |
678
|
|
|
$this->action = $view; |
679
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_md_details', |
680
|
|
|
'md' => $this->request->get('md')); |
681
|
|
|
} else { |
682
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
683
|
|
|
} |
684
|
|
|
$this->view = 'RedirectAfterCrud'; |
685
|
|
|
break; |
686
|
|
|
case 'admin_delete_love': |
687
|
|
|
$mdFactory = $this->_getMetadataFactory($this->_viewParams['group_id']); |
688
|
|
|
if($mdFactory->isValidLabel($this->request->get('md'))) { |
689
|
|
|
$this->action = $view; |
690
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_md_details', |
691
|
|
|
'md' => $this->request->get('md')); |
692
|
|
|
} else { |
693
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
694
|
|
|
} |
695
|
|
|
$this->view = 'RedirectAfterCrud'; |
696
|
|
|
break; |
697
|
|
|
case 'admin_display_love': |
698
|
|
|
$valid = false; |
699
|
|
|
// Required params: |
700
|
|
|
// md (string [a-z_]+) |
701
|
|
|
// loveid (int) |
702
|
|
|
|
703
|
|
|
// Sanitize |
704
|
|
|
$_mdLabel = $this->request->get('md'); |
705
|
|
|
$_loveId = (int) $this->request->get('loveid'); |
706
|
|
|
|
707
|
|
|
// Valid |
708
|
|
|
$md = null; |
709
|
|
|
$love = null; |
710
|
|
|
$this->validateMetadata($_mdLabel, $md); |
711
|
|
|
if($md !== null && $md->getLabel() !== 'status') { |
712
|
|
|
$valid = $this->validateLove($_loveId, $md, $love); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
if(!$valid) { |
716
|
|
|
$this->view = 'RedirectAfterCrud'; |
717
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
718
|
|
|
} |
719
|
|
|
else { |
720
|
|
|
$mdFactory = new Docman_MetadataFactory($this->groupId); |
721
|
|
|
$mdFactory->appendMetadataValueList($md, false); |
722
|
|
|
|
723
|
|
|
$this->view = 'Admin_MetadataDetailsUpdateLove'; |
724
|
|
|
$this->_viewParams['md'] = $md; |
725
|
|
|
$this->_viewParams['love'] = $love; |
726
|
|
|
} |
727
|
|
|
break; |
728
|
|
|
case 'admin_update_love': |
729
|
|
|
$valid = false; |
730
|
|
|
// Required params: |
731
|
|
|
// md (string [a-z_]+) |
732
|
|
|
// loveid (int) |
733
|
|
|
// |
734
|
|
|
// rank (beg, end, [0-9]+) |
735
|
|
|
// name |
736
|
|
|
// descr |
737
|
|
|
|
738
|
|
|
// Sanitize |
739
|
|
|
/// @todo sanitize md, rank, name, descr |
740
|
|
|
$_mdLabel = $this->request->get('md'); |
741
|
|
|
$_loveId = (int) $this->request->get('loveid'); |
742
|
|
|
$_rank = $this->request->get('rank'); |
743
|
|
|
$_name = $this->request->get('name'); |
744
|
|
|
$_descr = $this->request->get('descr'); |
745
|
|
|
|
746
|
|
|
// Valid |
747
|
|
|
$md = null; |
748
|
|
|
$love = null; |
749
|
|
|
$this->validateMetadata($_mdLabel, $md); |
750
|
|
|
if($md !== null && $md->getLabel() !== 'status') { |
751
|
|
|
$valid = $this->validateLove($_loveId, $md, $love); |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
if(!$valid) { |
755
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_md_or_love')); |
756
|
|
|
$this->view = 'RedirectAfterCrud'; |
757
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
758
|
|
|
} |
759
|
|
|
else { |
760
|
|
|
// Set parameters |
761
|
|
|
$love->setRank($_rank); |
762
|
|
|
$love->setName($_name); |
763
|
|
|
$love->setDescription($_descr); |
764
|
|
|
|
765
|
|
|
// define action |
766
|
|
|
$this->action = $view; |
767
|
|
|
$this->_actionParams['md'] = $md; |
768
|
|
|
$this->_actionParams['love'] = $love; |
769
|
|
|
} |
770
|
|
|
break; |
771
|
|
|
|
772
|
|
|
case 'admin_import_metadata_check': |
773
|
|
|
$ok = false; |
774
|
|
|
if($this->request->existAndNonEmpty('plugin_docman_metadata_import_group')) { |
775
|
|
|
$pm = ProjectManager::instance(); |
776
|
|
|
$srcGroup = $pm->getProjectFromAutocompleter($this->request->get('plugin_docman_metadata_import_group')); |
777
|
|
|
if ($srcGroup && !$srcGroup->isError()) { |
778
|
|
|
$this->_viewParams['sSrcGroupId'] = $srcGroup->getGroupId(); |
779
|
|
|
$this->view = 'Admin_MetadataImport'; |
780
|
|
|
$ok = true; |
781
|
|
|
} |
782
|
|
|
} |
783
|
|
|
if (!$ok) { |
784
|
|
|
$this->view = 'RedirectAfterCrud'; |
785
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
786
|
|
|
} |
787
|
|
|
break; |
788
|
|
|
|
789
|
|
|
case 'admin_import_metadata': |
790
|
|
|
if($this->request->existAndNonEmpty('confirm')) { |
791
|
|
|
|
792
|
|
|
if($this->request->existAndNonEmpty('plugin_docman_metadata_import_group')) { |
793
|
|
|
$pm = ProjectManager::instance(); |
794
|
|
|
$srcGroup = $pm->getProjectFromAutocompleter($this->request->get('plugin_docman_metadata_import_group')); |
795
|
|
|
$srcGroupId = $srcGroup->getGroupId(); |
796
|
|
|
$this->_actionParams['sSrcGroupId'] = $srcGroupId; |
797
|
|
|
$this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; |
798
|
|
|
|
799
|
|
|
$this->action = $view; |
800
|
|
|
} else { |
801
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'missing_param')); |
802
|
|
|
$this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'operation_canceled')); |
803
|
|
|
} |
804
|
|
|
} else { |
805
|
|
|
$this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'operation_canceled')); |
806
|
|
|
} |
807
|
|
|
$this->view = 'RedirectAfterCrud'; |
808
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); |
809
|
|
|
break; |
810
|
|
|
|
811
|
|
|
case 'admin_obsolete': |
812
|
|
|
$this->view = 'Admin_Obsolete'; |
813
|
|
|
break; |
814
|
|
|
|
815
|
|
|
case 'admin_lock_infos': |
816
|
|
|
$this->view = 'Admin_LockInfos'; |
817
|
|
|
break; |
818
|
|
|
|
819
|
|
|
case 'move': |
820
|
|
|
if (!$this->userCanWrite($item->getId()) || !$this->userCanWrite($item->getParentId())) { |
821
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_move')); |
822
|
|
|
$this->view = 'Details'; |
823
|
|
|
} else { |
824
|
|
|
if ($this->request->exist('quick_move')) { |
825
|
|
|
$this->action = 'move'; |
826
|
|
|
$this->view = null; |
827
|
|
|
} else { |
828
|
|
|
$this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); |
829
|
|
|
$this->view = ucfirst($view); |
830
|
|
|
} |
831
|
|
|
} |
832
|
|
|
break; |
833
|
|
|
case 'newGlobalDocument': |
834
|
|
|
if ($dpm->oneFolderIsWritable($user)) { |
835
|
|
|
$this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); |
836
|
|
|
$this->view = 'New_FolderSelection'; |
837
|
|
|
} else { |
838
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_create')); |
839
|
|
|
$this->view = $item->accept($get_show_view, $this->request->get('report')); |
840
|
|
|
} |
841
|
|
|
break; |
842
|
|
|
case 'newDocument': |
843
|
|
|
case 'newFolder': |
844
|
|
|
if ($this->request->exist('cancel')) { |
845
|
|
|
$this->_set_redirectView(); |
846
|
|
|
} else { |
847
|
|
|
if (!$this->userCanWrite($item->getId())) { |
848
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_create')); |
849
|
|
|
$this->view = 'Details'; |
850
|
|
|
} else { |
851
|
|
|
//$this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); |
852
|
|
|
$this->_viewParams['ordering'] = $this->request->get('ordering'); |
853
|
|
|
if($this->request->get('item_type') == PLUGIN_DOCMAN_ITEM_TYPE_FOLDER) { |
854
|
|
|
$view = 'newFolder'; |
855
|
|
|
} |
856
|
|
|
$this->view = ucfirst($view); |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
break; |
860
|
|
|
case 'monitor': |
861
|
|
|
if ($this->request->exist('monitor')) { |
862
|
|
|
$this->_actionParams['monitor'] = $this->request->get('monitor'); |
863
|
|
|
if ($this->request->exist('cascade')) { |
864
|
|
|
$this->_actionParams['cascade'] = $this->request->get('cascade'); |
865
|
|
|
} |
866
|
|
|
$this->_actionParams['item'] =& $item; |
867
|
|
|
$this->action = 'monitor'; |
868
|
|
|
} |
869
|
|
|
$this->_setView('Details'); |
870
|
|
|
break; |
871
|
|
|
case 'remove_monitoring': |
872
|
|
|
$this->_actionParams['listeners_to_delete'] = array(); |
873
|
|
|
if ($this->userCanManage($item->getId())) { |
874
|
|
|
if ($this->request->exist('listeners_to_delete')) { |
875
|
|
|
$um = UserManager::instance(); |
876
|
|
|
$vUserId = new Valid_UInt('listeners_to_delete'); |
877
|
|
|
if($this->request->validArray($vUserId)) { |
878
|
|
|
$userIds = $this->request->get('listeners_to_delete'); |
879
|
|
|
$users = array(); |
880
|
|
|
foreach ($userIds as $userId) { |
881
|
|
|
$users[] = $um->getUserById($userId); |
882
|
|
|
} |
883
|
|
|
$this->_actionParams['listeners_to_delete'] = $users; |
884
|
|
|
$this->_actionParams['item'] = $item; |
885
|
|
|
} |
886
|
|
|
} |
887
|
|
|
$this->action = 'remove_monitoring'; |
888
|
|
|
$this->_setView('Details'); |
889
|
|
|
} else { |
890
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'notifications_permission_denied')); |
891
|
|
|
$this->_setView('Details'); |
892
|
|
|
} |
893
|
|
|
break; |
894
|
|
|
|
895
|
|
|
case 'add_monitoring': |
896
|
|
|
$this->_actionParams['listeners_to_add'] = array(); |
897
|
|
|
$this->_actionParams['invalid_users'] = false; |
898
|
|
|
if ($this->userCanManage($item->getId())) { |
899
|
|
|
if ($this->request->exist('listeners_to_add')) { |
900
|
|
|
$um = UserManager::instance(); |
901
|
|
|
$vUser = new Valid_Text('listeners_to_add'); |
902
|
|
|
if($this->request->valid($vUser)) { |
903
|
|
|
$usernames = array_map('trim', preg_split('/[,;]/', $this->request->get('listeners_to_add'))); |
904
|
|
|
$users = array(); |
905
|
|
|
$vUserName = new Valid_String(); |
906
|
|
|
$vUserName->required(); |
907
|
|
|
foreach ($usernames as $username) { |
908
|
|
|
if ($vUserName->validate($username) && $user = $um->findUser($username)) { |
909
|
|
|
$users[] =$user; |
910
|
|
|
} else { |
911
|
|
|
$this->_actionParams['invalid_users'] = true; |
912
|
|
|
} |
913
|
|
|
} |
914
|
|
|
if ($this->request->exist('monitor_cascade')) { |
915
|
|
|
$this->_actionParams['monitor_cascade'] = $this->request->get('monitor_cascade'); |
916
|
|
|
} |
917
|
|
|
$this->_actionParams['listeners_to_add'] = $users; |
918
|
|
|
$this->_actionParams['item'] = $item; |
919
|
|
|
} |
920
|
|
|
} |
921
|
|
|
$this->action = 'add_monitoring'; |
922
|
|
|
$this->_setView('Details'); |
923
|
|
|
} else { |
924
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'notifications_permission_denied')); |
925
|
|
|
$this->_setView('Details'); |
926
|
|
|
} |
927
|
|
|
break; |
928
|
|
|
|
929
|
|
|
case 'move_here': |
930
|
|
|
if (!$this->request->exist('item_to_move')) { |
931
|
|
|
$this->feedback->log('error', 'Missing parameter.'); |
932
|
|
|
$this->view = 'DocmanError'; |
933
|
|
|
} else { |
934
|
|
|
$item_to_move =& $item_factory->getItemFromDb($this->request->get('item_to_move')); |
935
|
|
|
$this->view = null; |
936
|
|
|
if ($this->request->exist('confirm')) { |
937
|
|
|
if (!$item_to_move || !($this->userCanWrite($item->getId()) && $this->userCanWrite($item_to_move->getId()) && $this->userCanWrite($item_to_move->getParentId()))) { |
938
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_move')); |
939
|
|
|
$this->_set_moveView_errorPerms(); |
940
|
|
|
} else { |
941
|
|
|
$this->action = 'move'; |
942
|
|
|
} |
943
|
|
|
} |
944
|
|
|
if (!$this->view) { |
945
|
|
|
$this->_set_redirectView(); |
946
|
|
|
} |
947
|
|
|
} |
948
|
|
|
break; |
949
|
|
|
case 'permissions': |
950
|
|
|
if (!$this->userCanManage($item->getId())) { |
951
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_perms')); |
952
|
|
|
$this->view = 'Details'; |
953
|
|
|
} else { |
954
|
|
|
$this->action = 'permissions'; |
955
|
|
|
$this->view = 'Details'; |
956
|
|
|
} |
957
|
|
|
break; |
958
|
|
|
case 'confirmDelete': |
959
|
|
|
if (!$this->userCanWrite($item->getId()) || !$this->userCanWrite($item->getParentId())) { |
960
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_delete')); |
961
|
|
|
$this->view = 'Details'; |
962
|
|
|
} else { |
963
|
|
|
$this->view = 'Delete'; |
964
|
|
|
} |
965
|
|
|
break; |
966
|
|
|
case 'action_new_version': |
967
|
|
|
if (!$this->userCanWrite($item->getId())) { |
968
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); |
969
|
|
|
$this->view = 'Details'; |
970
|
|
|
} else { |
971
|
|
|
$dPm = $this->_getPermissionsManager(); |
972
|
|
|
if($dPm->getLockFactory()->itemIsLocked($item)) { |
973
|
|
|
$this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docman', 'event_lock_add')); |
974
|
|
|
} |
975
|
|
|
$this->view = 'NewVersion'; |
976
|
|
|
} |
977
|
|
|
break; |
978
|
|
|
case 'action_update': |
979
|
|
|
if (!$this->userCanWrite($item->getId())) { |
980
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); |
981
|
|
|
$this->view = 'Details'; |
982
|
|
|
} else { |
983
|
|
|
$this->view = 'Update'; |
984
|
|
|
} |
985
|
|
|
break; |
986
|
|
|
|
987
|
|
|
case 'action_copy': |
988
|
|
|
//@XSS: validate action against a regexp. |
989
|
|
|
$_action = $this->request->get('orig_action'); |
990
|
|
|
$_id = (int) $this->request->get('orig_id'); |
991
|
|
|
$this->_actionParams['item'] = $item; |
992
|
|
|
|
993
|
|
|
$this->action = $view; |
994
|
|
|
if(!$this->request->exist('ajax_copy')) { |
995
|
|
|
$this->_viewParams['default_url_params'] = array('action' => $_action, |
996
|
|
|
'id' => $_id); |
997
|
|
|
$this->view = 'RedirectAfterCrud'; |
998
|
|
|
} |
999
|
|
|
break; |
1000
|
|
|
|
1001
|
|
|
case 'action_cut': |
1002
|
|
|
$_action = $this->request->get('orig_action'); |
1003
|
|
|
$_id = (int) $this->request->get('orig_id'); |
1004
|
|
|
$this->_actionParams['item'] = $item; |
1005
|
|
|
|
1006
|
|
|
$this->action = $view; |
1007
|
|
|
if(!$this->request->exist('ajax_cut')) { |
1008
|
|
|
$this->_viewParams['default_url_params'] = array('action' => $_action, |
1009
|
|
|
'id' => $_id); |
1010
|
|
|
$this->view = 'RedirectAfterCrud'; |
1011
|
|
|
} |
1012
|
|
|
break; |
1013
|
|
|
|
1014
|
|
|
case 'action_paste': |
1015
|
|
|
$itemToPaste = null; |
1016
|
|
|
$mode = null; |
1017
|
|
|
$allowed = $this->checkPasteIsAllowed($item, $itemToPaste, $mode); |
1018
|
|
|
if(!$allowed) { |
1019
|
|
|
$this->view = 'Details'; |
1020
|
|
|
} |
1021
|
|
|
else { |
1022
|
|
|
$this->_viewParams['itemToPaste'] = $itemToPaste; |
1023
|
|
|
$this->_viewParams['srcMode'] = $mode; |
1024
|
|
|
$this->view = 'Paste'; |
1025
|
|
|
} |
1026
|
|
|
break; |
1027
|
|
|
|
1028
|
|
|
case 'paste_cancel': |
1029
|
|
|
// intend to be only called through ajax call |
1030
|
|
|
$item_factory->delCopyPreference(); |
1031
|
|
|
$item_factory->delCutPreference(); |
1032
|
|
|
break; |
1033
|
|
|
|
1034
|
|
|
case 'paste': |
1035
|
|
|
if($this->request->exist('cancel')) { |
1036
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'show'); |
1037
|
|
|
$this->view = 'RedirectAfterCrud'; |
1038
|
|
|
} else { |
1039
|
|
|
$itemToPaste = null; |
1040
|
|
|
$mode = null; |
1041
|
|
|
$allowed = $this->checkPasteIsAllowed($item, $itemToPaste, $mode); |
1042
|
|
|
if(!$allowed) { |
1043
|
|
|
$this->view = 'Details'; |
1044
|
|
|
} |
1045
|
|
|
else { |
1046
|
|
|
$this->_viewParams['importMd'] = false; |
1047
|
|
|
if($this->userCanAdmin()) { |
1048
|
|
|
if($this->request->exist('import_md') && |
1049
|
|
|
$this->request->get('import_md') == '1') { |
1050
|
|
|
$this->_viewParams['importMd'] = true; |
1051
|
|
|
} |
1052
|
|
|
} |
1053
|
|
|
$this->_viewParams['item'] = $item; |
1054
|
|
|
$this->_viewParams['rank'] = $this->request->get('rank'); |
1055
|
|
|
$this->_viewParams['itemToPaste'] = $itemToPaste; |
1056
|
|
|
$this->_viewParams['srcMode'] = $mode; |
1057
|
|
|
/*$this->action = $view; |
1058
|
|
|
|
1059
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'show', |
1060
|
|
|
'id' => $item->getId()); |
1061
|
|
|
$this->view = 'RedirectAfterCrud';*/ |
1062
|
|
|
$this->_viewParams['item'] = $item; |
1063
|
|
|
$this->_viewParams['rank'] = $this->request->get('rank'); |
1064
|
|
|
$this->_viewParams['itemToPaste'] = $itemToPaste; |
1065
|
|
|
$this->_viewParams['srcMode'] = $mode; |
1066
|
|
|
$this->view = 'PasteInProgress'; |
1067
|
|
|
} |
1068
|
|
|
} |
1069
|
|
|
break; |
1070
|
|
|
|
1071
|
|
|
case 'approval_create': |
1072
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1073
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1074
|
|
|
$this->view = 'Details'; |
1075
|
|
|
} else { |
1076
|
|
|
$this->view = 'ApprovalCreate'; |
1077
|
|
|
} |
1078
|
|
|
break; |
1079
|
|
|
|
1080
|
|
|
case 'approval_delete': |
1081
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1082
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1083
|
|
|
$this->view = 'Details'; |
1084
|
|
|
} else { |
1085
|
|
|
if ($this->request->exist('confirm')) { |
1086
|
|
|
$this->action = $view; |
1087
|
|
|
$this->_actionParams['item'] = $item; |
1088
|
|
|
|
1089
|
|
|
// Version |
1090
|
|
|
$vVersion = new Valid_UInt('version'); |
1091
|
|
|
$vVersion->required(); |
1092
|
|
|
if($this->request->valid($vVersion)) { |
1093
|
|
|
$this->_actionParams['version'] = $this->request->get('version'); |
1094
|
|
|
} else { |
1095
|
|
|
$this->_actionParams['version'] = null; |
1096
|
|
|
} |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'details', |
1100
|
|
|
'section' => 'approval', |
1101
|
|
|
'id' => $item->getId()); |
1102
|
|
|
$this->view = 'RedirectAfterCrud'; |
1103
|
|
|
} |
1104
|
|
|
break; |
1105
|
|
|
|
1106
|
|
|
case 'approval_update': |
1107
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1108
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1109
|
|
|
$this->view = 'Details'; |
1110
|
|
|
} else { |
1111
|
|
|
$this->_actionParams['item'] = $item; |
1112
|
|
|
|
1113
|
|
|
// Settings |
1114
|
|
|
$this->_actionParams['status'] = (int) $this->request->get('status'); |
1115
|
|
|
$this->_actionParams['description'] = $this->request->get('description'); |
1116
|
|
|
$this->_actionParams['notification'] = (int) $this->request->get('notification'); |
1117
|
|
|
$this->_actionParams['reminder'] = $this->request->get('reminder'); |
1118
|
|
|
$this->_actionParams['occurence'] = (int) $this->request->get('occurence'); |
1119
|
|
|
$this->_actionParams['period'] = (int) $this->request->get('period'); |
1120
|
|
|
|
1121
|
|
|
// Users |
1122
|
|
|
$this->_actionParams['user_list'] = $this->request->get('user_list'); |
1123
|
|
|
$this->_actionParams['ugroup_list'] = null; |
1124
|
|
|
if(is_array($this->request->get('ugroup_list'))) { |
1125
|
|
|
$this->_actionParams['ugroup_list'] = array_map('intval', $this->request->get('ugroup_list')); |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
// Selected users |
1129
|
|
|
$this->_actionParams['sel_user'] = null; |
1130
|
|
|
if(is_array($this->request->get('sel_user'))) { |
1131
|
|
|
$this->_actionParams['sel_user'] = array_map('intval', $this->request->get('sel_user')); |
1132
|
|
|
} |
1133
|
|
|
$allowedAct = array('100', 'mail', 'del'); |
1134
|
|
|
$this->_actionParams['sel_user_act'] = null; |
1135
|
|
|
if(in_array($this->request->get('sel_user_act'), $allowedAct)) { |
1136
|
|
|
$this->_actionParams['sel_user_act'] = $this->request->get('sel_user_act'); |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
// Resend |
1140
|
|
|
$this->_actionParams['resend_notif'] = false; |
1141
|
|
|
if($this->request->get('resend_notif') == 'yes') { |
1142
|
|
|
$this->_actionParams['resend_notif'] = true; |
1143
|
|
|
} |
1144
|
|
|
|
1145
|
|
|
// Version |
1146
|
|
|
$vVersion = new Valid_UInt('version'); |
1147
|
|
|
$vVersion->required(); |
1148
|
|
|
if($this->request->valid($vVersion)) { |
1149
|
|
|
$this->_actionParams['version'] = $this->request->get('version'); |
1150
|
|
|
} else { |
1151
|
|
|
$this->_actionParams['version'] = null; |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
|
// Import |
1155
|
|
|
$vImport = new Valid_WhiteList('app_table_import', array('copy', 'reset', 'empty')); |
1156
|
|
|
$vImport->required(); |
1157
|
|
|
$this->_actionParams['import'] = $this->request->getValidated('app_table_import', $vImport, false); |
1158
|
|
|
|
1159
|
|
|
// Owner |
1160
|
|
|
$vOwner = new Valid_String('table_owner'); |
1161
|
|
|
$vOwner->required(); |
1162
|
|
|
$this->_actionParams['table_owner'] = $this->request->getValidated('table_owner', $vOwner, false); |
1163
|
|
|
|
1164
|
|
|
// |
1165
|
|
|
// Special handeling of table deletion |
1166
|
|
|
if($this->_actionParams['status'] == PLUGIN_DOCMAN_APPROVAL_TABLE_DELETED) { |
1167
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'approval_create', |
1168
|
|
|
'delete' => 'confirm', |
1169
|
|
|
'id' => $item->getId()); |
1170
|
|
|
} else { |
1171
|
|
|
// Action! |
1172
|
|
|
$this->action = $view; |
1173
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'approval_create', |
1174
|
|
|
'id' => $item->getId()); |
1175
|
|
|
} |
1176
|
|
|
if($this->_actionParams['version'] !== null) { |
1177
|
|
|
$this->_viewParams['default_url_params']['version'] = $this->_actionParams['version']; |
1178
|
|
|
} |
1179
|
|
|
$this->view = 'RedirectAfterCrud'; |
1180
|
|
|
} |
1181
|
|
|
break; |
1182
|
|
|
|
1183
|
|
|
case 'approval_upd_user': |
1184
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1185
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1186
|
|
|
$this->view = 'Details'; |
1187
|
|
|
} else { |
1188
|
|
|
$this->_actionParams['item'] = $item; |
1189
|
|
|
$this->_actionParams['user_id'] = (int) $this->request->get('user_id'); |
1190
|
|
|
$this->_actionParams['rank'] = $this->request->get('rank'); |
1191
|
|
|
$this->action = $view; |
1192
|
|
|
|
1193
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'approval_create', |
1194
|
|
|
'id' => $item->getId()); |
1195
|
|
|
$this->view = 'RedirectAfterCrud'; |
1196
|
|
|
} |
1197
|
|
|
break; |
1198
|
|
|
|
1199
|
|
|
case 'approval_del_user': |
1200
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1201
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1202
|
|
|
$this->view = 'Details'; |
1203
|
|
|
} else { |
1204
|
|
|
$this->_actionParams['item'] = $item; |
1205
|
|
|
$this->_actionParams['user_id'] = (int) $this->request->get('user_id'); |
1206
|
|
|
$this->action = $view; |
1207
|
|
|
|
1208
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'approval_create', |
1209
|
|
|
'id' => $item->getId()); |
1210
|
|
|
$this->view = 'RedirectAfterCrud'; |
1211
|
|
|
} |
1212
|
|
|
break; |
1213
|
|
|
|
1214
|
|
|
case 'approval_user_commit': |
1215
|
|
|
$atf =& Docman_ApprovalTableFactoriesFactory::getFromItem($item); |
1216
|
|
|
$table = $atf->getTable(); |
1217
|
|
|
$atrf =& new Docman_ApprovalTableReviewerFactory($table, $item); |
1218
|
|
|
if (!$this->userCanRead($item->getId()) |
1219
|
|
|
|| !$atrf->isReviewer($user->getId()) |
1220
|
|
|
|| !$table->isEnabled()) { |
1221
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1222
|
|
|
$this->view = 'Details'; |
1223
|
|
|
} |
1224
|
|
|
else { |
1225
|
|
|
$this->_actionParams['item'] = $item; |
1226
|
|
|
|
1227
|
|
|
$svState = 0; |
1228
|
|
|
$sState = (int) $this->request->get('state'); |
1229
|
|
|
if($sState >= 0 && $sState < 5) { |
1230
|
|
|
$svState = $sState; |
1231
|
|
|
} |
1232
|
|
|
$this->_actionParams['svState'] = $svState; |
1233
|
|
|
|
1234
|
|
|
$this->_actionParams['sVersion'] = null; |
1235
|
|
|
if($this->request->exist('version')) { |
1236
|
|
|
$sVersion = (int) $this->request->get('version'); |
1237
|
|
|
switch($item_factory->getItemTypeForItem($item)) { |
1238
|
|
|
case PLUGIN_DOCMAN_ITEM_TYPE_WIKI: |
1239
|
|
|
if($sVersion <= 0) { |
1240
|
|
|
$sVersion = null; |
1241
|
|
|
} |
1242
|
|
|
case PLUGIN_DOCMAN_ITEM_TYPE_FILE: |
1243
|
|
|
case PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE: |
1244
|
|
|
// assume ok: do nothing. |
1245
|
|
|
break; |
1246
|
|
|
default: |
1247
|
|
|
$sVersion = null; |
1248
|
|
|
} |
1249
|
|
|
$this->_actionParams['sVersion'] = $sVersion; |
1250
|
|
|
} |
1251
|
|
|
$this->_actionParams['usComment'] = $this->request->get('comment'); |
1252
|
|
|
$this->_actionParams['monitor'] = (int) $this->request->get('monitor'); |
1253
|
|
|
|
1254
|
|
|
$this->action = $view; |
1255
|
|
|
|
1256
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'details', |
1257
|
|
|
'section' => 'approval', |
1258
|
|
|
'id' => $item->getId()); |
1259
|
|
|
$this->view = 'RedirectAfterCrud'; |
1260
|
|
|
} |
1261
|
|
|
break; |
1262
|
|
|
|
1263
|
|
|
case 'approval_notif_resend': |
1264
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1265
|
|
|
$this->feedback->log('error', $this->txt('error_perms_edit')); |
1266
|
|
|
$this->view = 'Details'; |
1267
|
|
|
} else { |
1268
|
|
|
$this->action = $view; |
1269
|
|
|
$this->_actionParams['item'] = $item; |
1270
|
|
|
|
1271
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'approval_create', |
1272
|
|
|
'id' => $item->getId()); |
1273
|
|
|
$this->view = 'RedirectAfterCrud'; |
1274
|
|
|
} |
1275
|
|
|
break; |
1276
|
|
|
|
1277
|
|
|
case 'edit': |
1278
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1279
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); |
1280
|
|
|
$this->view = 'Details'; |
1281
|
|
|
} else { |
1282
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
1283
|
|
|
$mdFactory->appendAllListOfValuesToItem($item); |
1284
|
|
|
$this->view = 'Edit'; |
1285
|
|
|
} |
1286
|
|
|
break; |
1287
|
|
|
case 'delete': |
1288
|
|
|
if (!($this->userCanWrite($item->getId()) && $this->userCanWrite($item->getParentId()))) { |
1289
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_delete')); |
1290
|
|
|
$this->_set_deleteView_errorPerms(); |
1291
|
|
|
} else if ($this->request->exist('confirm')) { |
1292
|
|
|
$this->action = $view; |
1293
|
|
|
$this->_set_redirectView(); |
1294
|
|
|
} else { |
1295
|
|
|
$this->view = 'Details'; |
1296
|
|
|
} |
1297
|
|
|
break; |
1298
|
|
|
|
1299
|
|
|
case 'deleteVersion': |
1300
|
|
|
if (!($this->userCanWrite($item->getId()) && $this->userCanWrite($item->getParentId()))) { |
1301
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_delete')); |
1302
|
|
|
$this->_set_deleteView_errorPerms(); |
1303
|
|
|
} else if ($this->request->exist('confirm')) { |
1304
|
|
|
$this->action = $view; |
1305
|
|
|
$this->_set_redirectView(); |
1306
|
|
|
} else { |
1307
|
|
|
$this->view = 'Details'; |
1308
|
|
|
} |
1309
|
|
|
break; |
1310
|
|
|
|
1311
|
|
|
case 'createFolder': |
1312
|
|
|
case 'createDocument': |
1313
|
|
|
case 'createItem': |
1314
|
|
|
if ($this->request->exist('cancel')) { |
1315
|
|
|
$this->_set_redirectView(); |
1316
|
|
|
} else { |
1317
|
|
|
$i = $this->request->get('item'); |
1318
|
|
|
if (!$i || !isset($i['parent_id'])) { |
1319
|
|
|
$this->feedback->log('error', 'Missing parameter.'); |
1320
|
|
|
$this->view = 'DocmanError'; |
1321
|
|
|
} else { |
1322
|
|
|
$parent =& $item_factory->getItemFromDb($i['parent_id']); |
1323
|
|
|
if (!$parent || $parent->getGroupId() != $this->getGroupId() || !$this->userCanWrite($parent->getId())) { |
1324
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_create')); |
1325
|
|
|
$this->_set_createItemView_errorParentDoesNotExist($item, $get_show_view); |
1326
|
|
|
} else { |
1327
|
|
|
//Validations |
1328
|
|
|
$new_item = $this->createItemFromUserInput(); |
1329
|
|
|
|
1330
|
|
|
$valid = $this->_validateRequest(array_merge($new_item->accept(new Docman_View_GetFieldsVisitor()), |
1331
|
|
|
$new_item->accept(new Docman_View_GetSpecificFieldsVisitor(), array('request' => &$this->request)))); |
1332
|
|
|
|
1333
|
|
|
if ($user->isMember($this->getGroupId(), 'A') || $user->isMember($this->getGroupId(), 'N1') || $user->isMember($this->getGroupId(), 'N2')) { |
1334
|
|
|
$news = $this->request->get('news'); |
1335
|
|
|
if ($news) { |
1336
|
|
|
$is_news_details = isset($news['details']) && trim($news['details']); |
1337
|
|
|
$is_news_summary = isset($news['summary']) && trim($news['summary']); |
1338
|
|
|
if ($is_news_details && !$is_news_summary) { |
1339
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_create_news_summary')); |
1340
|
|
|
$valid = false; |
1341
|
|
|
} |
1342
|
|
|
if (!$is_news_details && $is_news_summary) { |
1343
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_create_news_details')); |
1344
|
|
|
$valid = false; |
1345
|
|
|
} |
1346
|
|
|
} |
1347
|
|
|
} |
1348
|
|
|
|
1349
|
|
|
if ($valid) { |
1350
|
|
|
$this->action = $view; |
1351
|
|
|
$this->_set_redirectView(); |
1352
|
|
|
} else { |
1353
|
|
|
// Propagate return page |
1354
|
|
|
$this->_viewParams['token'] = $this->request->get('token'); |
1355
|
|
|
|
1356
|
|
|
$this->_viewParams['force_item'] = $new_item; |
1357
|
|
|
$this->_viewParams['force_news'] = $this->request->get('news'); |
1358
|
|
|
$this->_viewParams['force_permissions'] = $this->request->get('permissions'); |
1359
|
|
|
$this->_viewParams['force_ordering'] = $this->request->get('ordering'); |
1360
|
|
|
$this->_viewParams['display_permissions'] = $this->request->exist('user_has_displayed_permissions'); |
1361
|
|
|
$this->_viewParams['display_news'] = $this->request->exist('user_has_displayed_news'); |
1362
|
|
|
$this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); |
1363
|
|
|
$this->_set_createItemView_afterCreate($view); |
1364
|
|
|
} |
1365
|
|
|
} |
1366
|
|
|
} |
1367
|
|
|
} |
1368
|
|
|
break; |
1369
|
|
|
case 'update': |
1370
|
|
|
$this->_viewParams['recurseOnDocs'] = false; |
1371
|
|
|
$this->_actionParams['recurseOnDocs'] = false; |
1372
|
|
|
if($this->request->get('recurse_on_doc') == 1) { |
1373
|
|
|
$this->_viewParams['recurseOnDocs'] = true; |
1374
|
|
|
$this->_actionParams['recurseOnDocs'] = true; |
1375
|
|
|
} |
1376
|
|
|
case 'update_wl': |
1377
|
|
|
case 'new_version': |
1378
|
|
|
if (!$this->userCanWrite($item->getId())) { |
1379
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); |
1380
|
|
|
$this->view = 'Details'; |
1381
|
|
|
} else { |
1382
|
|
|
// For properties update ('update' action), we need to confirm |
1383
|
|
|
// the recursive application of metadata update. |
1384
|
|
|
if($view == 'update' && |
1385
|
|
|
$this->request->exist('recurse') && |
1386
|
|
|
!$this->request->exist('cancel')) { |
1387
|
|
|
$this->_viewParams['recurse'] = $this->request->get('recurse'); |
1388
|
|
|
if(!$this->request->exist('validate_recurse')) { |
1389
|
|
|
$updateConfirmed = false; |
1390
|
|
|
} elseif($this->request->get('validate_recurse') != 'true') { |
1391
|
|
|
$updateConfirmed = false; |
1392
|
|
|
} else { |
1393
|
|
|
$updateConfirmed = true; |
1394
|
|
|
} |
1395
|
|
|
} else { |
1396
|
|
|
$updateConfirmed = true; |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
$valid = true; |
1400
|
|
|
if ($this->request->exist('confirm')) { |
1401
|
|
|
//Validations |
1402
|
|
|
if ($view == 'update') { |
1403
|
|
|
$this->updateMetadataFromUserInput($item); |
1404
|
|
|
$valid = $this->_validateRequest($item->accept(new Docman_View_GetFieldsVisitor())); |
1405
|
|
|
} else { |
1406
|
|
|
$this->updateItemFromUserInput($item); |
1407
|
|
|
$valid = (($this->_validateApprovalTable($this->request, $item))&&($this->_validateRequest($item->accept(new Docman_View_GetSpecificFieldsVisitor(), array('request' => &$this->request))))); |
1408
|
|
|
} |
1409
|
|
|
//Actions |
1410
|
|
|
if ($valid && $updateConfirmed) { |
1411
|
|
|
if ($view == 'update_wl') { |
1412
|
|
|
$this->action = 'update'; |
1413
|
|
|
} else { |
1414
|
|
|
$this->action = $view; |
1415
|
|
|
} |
1416
|
|
|
} |
1417
|
|
|
} |
1418
|
|
|
//Views |
1419
|
|
|
if ($valid && $updateConfirmed) { |
1420
|
|
|
if ($redirect_to = Docman_Token::retrieveUrl($this->request->get('token'))) { |
1421
|
|
|
$this->_viewParams['redirect_to'] = $redirect_to; |
1422
|
|
|
} |
1423
|
|
|
$this->view = 'RedirectAfterCrud'; |
1424
|
|
|
} else { |
1425
|
|
|
if ($view == 'update_wl') { |
1426
|
|
|
$this->view = 'Update'; |
1427
|
|
|
} else if ($view == 'new_version') { |
1428
|
|
|
// Keep fields values |
1429
|
|
|
$v = $this->request->get('version'); |
1430
|
|
|
$this->_viewParams['label'] = $v['label']; |
1431
|
|
|
$this->_viewParams['changelog'] = $v['changelog']; |
1432
|
|
|
if ($item instanceof Docman_EmbeddedFile) { |
1433
|
|
|
$v = $item->getCurrentVersion(); |
1434
|
|
|
$v->setContent($this->request->get('content')); |
1435
|
|
|
} |
1436
|
|
|
$this->view = 'NewVersion'; |
1437
|
|
|
} else { |
1438
|
|
|
$mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); |
1439
|
|
|
$mdFactory->appendAllListOfValuesToItem($item); |
1440
|
|
|
if($this->request->existAndNonEmpty('token')) { |
1441
|
|
|
// propagate the token so the user will be |
1442
|
|
|
// redirected to the original page even after |
1443
|
|
|
// several properties update errors or |
1444
|
|
|
// confirmations. |
1445
|
|
|
$this->_viewParams['token'] = $this->request->get('token'); |
1446
|
|
|
} |
1447
|
|
|
$this->_viewParams['updateConfirmed'] = $updateConfirmed; |
1448
|
|
|
// The item may have changed (new user input) |
1449
|
|
|
unset($this->_viewParams['item']); |
1450
|
|
|
$this->_viewParams['item'] =& $item; |
1451
|
|
|
|
1452
|
|
|
$this->view = 'Edit'; |
1453
|
|
|
} |
1454
|
|
|
} |
1455
|
|
|
} |
1456
|
|
|
break; |
1457
|
|
|
case 'change_view': |
1458
|
|
|
$this->action = $view; |
1459
|
|
|
break; |
1460
|
|
|
case 'install': |
1461
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_alreadyinstalled')); |
1462
|
|
|
$this->view = 'DocmanError'; |
1463
|
|
|
break; |
1464
|
|
|
case 'search': |
1465
|
|
|
$this->view = 'Table'; |
1466
|
|
|
break; |
1467
|
|
|
case 'positionWithinFolder': |
1468
|
|
|
$this->_viewParams['force_ordering'] = $this->request->get('default_position'); |
1469
|
|
|
$this->_viewParams['exclude'] = $this->request->get('exclude'); |
1470
|
|
|
$this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); |
1471
|
|
|
$this->view = ucfirst($view); |
1472
|
|
|
break; |
1473
|
|
|
case 'permissionsForItem': |
1474
|
|
|
$this->_viewParams['user_can_manage'] = $this->userCanManage($item->getId()); |
1475
|
|
|
$this->view = ucfirst($view); |
1476
|
|
|
break; |
1477
|
|
|
case 'report_settings': |
1478
|
|
|
$this->view = 'ReportSettings'; |
1479
|
|
|
break; |
1480
|
|
|
case 'report_del': |
1481
|
|
|
if($this->request->exist('report_id')) { |
1482
|
|
|
$this->_actionParams['sReportId'] = (int) $this->request->get('report_id'); |
1483
|
|
|
$this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; |
1484
|
|
|
|
1485
|
|
|
$this->action = $view; |
1486
|
|
|
} |
1487
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'report_settings'); |
1488
|
|
|
$this->view = 'RedirectAfterCrud'; |
1489
|
|
|
|
1490
|
|
|
break; |
1491
|
|
|
case 'report_upd': |
1492
|
|
|
if($this->request->exist('report_id')) { |
1493
|
|
|
$this->_actionParams['sReportId'] = (int) $this->request->get('report_id'); |
1494
|
|
|
$this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; |
1495
|
|
|
$usScope = $this->request->get('scope'); |
1496
|
|
|
if($usScope === 'I' || $usScope === 'P') { |
1497
|
|
|
$this->_actionParams['sScope'] = $usScope; |
1498
|
|
|
} |
1499
|
|
|
$this->_actionParams['description'] = $this->request->get('description'); |
1500
|
|
|
$this->_actionParams['title'] = $this->request->get('title'); |
1501
|
|
|
$this->_actionParams['sImage'] = (int) $this->request->get('image'); |
1502
|
|
|
|
1503
|
|
|
$this->action = $view; |
1504
|
|
|
} |
1505
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'report_settings'); |
1506
|
|
|
$this->view = 'RedirectAfterCrud'; |
1507
|
|
|
break; |
1508
|
|
|
|
1509
|
|
|
case 'report_import': |
1510
|
|
|
if($this->request->exist('import_search_report_from_group')) { |
1511
|
|
|
$pm = ProjectManager::instance(); |
1512
|
|
|
$srcGroup = $pm->getProjectFromAutocompleter($this->request->get('import_search_report_from_group')); |
1513
|
|
|
if ($srcGroup && !$srcGroup->isError()) { |
1514
|
|
|
$this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; |
1515
|
|
|
$this->_actionParams['sImportGroupId'] = $srcGroup->getGroupId(); |
1516
|
|
|
$this->_actionParams['sImportReportId'] = null; |
1517
|
|
|
if($this->request->exist('import_report_id') && trim($this->request->get('import_report_id')) != '') { |
1518
|
|
|
$this->_actionParams['sImportReportId'] = (int) $this->request->get('import_report_id'); |
1519
|
|
|
} |
1520
|
|
|
$this->action = $view; |
1521
|
|
|
} |
1522
|
|
|
} |
1523
|
|
|
|
1524
|
|
|
$this->_viewParams['default_url_params'] = array('action' => 'report_settings'); |
1525
|
|
|
$this->view = 'RedirectAfterCrud'; |
1526
|
|
|
break; |
1527
|
|
|
|
1528
|
|
|
case 'action_lock_add': |
1529
|
|
|
$this->_actionParams['item'] = $item; |
1530
|
|
|
$this->action = 'action_lock_add'; |
1531
|
|
|
break; |
1532
|
|
|
|
1533
|
|
|
case 'action_lock_del': |
1534
|
|
|
$this->_actionParams['item'] = $item; |
1535
|
|
|
$this->action = 'action_lock_del'; |
1536
|
|
|
break; |
1537
|
|
|
|
1538
|
|
|
case 'ajax_reference_tooltip': |
1539
|
|
|
$this->view = 'AjaxReferenceTooltip'; |
1540
|
|
|
break; |
1541
|
|
|
|
1542
|
|
|
default: |
1543
|
|
|
$purifier = Codendi_HTMLPurifier::instance(); |
1544
|
|
|
die($purifier->purify($view) . ' is not supported'); |
|
|
|
|
1545
|
|
|
break; |
|
|
|
|
1546
|
|
|
} |
1547
|
|
|
} |
1548
|
|
|
|
1549
|
|
|
function getProperty($name) { |
1550
|
|
|
$info =& $this->plugin->getPluginInfo(); |
1551
|
|
|
return $info->getPropertyValueForName($name); |
1552
|
|
|
} |
1553
|
|
|
var $item_factory; |
1554
|
|
|
function &_getItemFactory() { |
1555
|
|
|
if (!$this->item_factory) { |
1556
|
|
|
$this->item_factory =& new Docman_ItemFactory(); |
1557
|
|
|
} |
1558
|
|
|
return $this->item_factory; |
1559
|
|
|
} |
1560
|
|
|
|
1561
|
|
|
var $metadataFactory; |
1562
|
|
|
function &_getMetadataFactory($groupId) { |
1563
|
|
|
if(!isset($metadataFactory[$groupId])) { |
|
|
|
|
1564
|
|
|
$metadataFactory[$groupId] = new Docman_MetadataFactory($groupId); |
1565
|
|
|
} |
1566
|
|
|
return $metadataFactory[$groupId]; |
1567
|
|
|
} |
1568
|
|
|
|
1569
|
|
|
function forceView($view) { |
1570
|
|
|
$this->view = $view; |
1571
|
|
|
} |
1572
|
|
|
|
1573
|
|
|
function _validateApprovalTable($request, $item) { |
1574
|
|
|
$atf = Docman_ApprovalTableFactoriesFactory::getFromItem($item); |
1575
|
|
|
if($atf && $atf->tableExistsForItem()) { |
1576
|
|
|
$vAppTable = new Valid_WhiteList('app_table_import', array('copy', 'reset', 'empty')); |
1577
|
|
|
$vAppTable->required(); |
1578
|
|
|
if (!$request->valid($vAppTable)) { |
1579
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_no_option')); |
1580
|
|
|
return false; |
1581
|
|
|
} |
1582
|
|
|
} |
1583
|
|
|
return true; |
1584
|
|
|
} |
1585
|
|
|
|
1586
|
|
|
function _validateRequest($fields) { |
1587
|
|
|
$valid = true; |
1588
|
|
|
foreach($fields as $field) { |
1589
|
|
|
$validatorList = null; |
1590
|
|
|
if(is_a($field, 'Docman_MetadataHtml')) { |
1591
|
|
|
$fv = $field->getValidator($this->request); |
1592
|
|
|
if($fv !== null) { |
1593
|
|
|
if(!is_array($fv)) { |
1594
|
|
|
$validatorList = array($fv); |
1595
|
|
|
} |
1596
|
|
|
else { |
1597
|
|
|
$validatorList =& $fv; |
1598
|
|
|
} |
1599
|
|
|
} |
1600
|
|
|
} |
1601
|
|
|
else { |
1602
|
|
|
if (isset($field['validator'])) { |
1603
|
|
|
if (!is_array($field['validator'])) { |
1604
|
|
|
$validatorList = array($field['validator']); |
1605
|
|
|
} |
1606
|
|
|
else { |
1607
|
|
|
$validatorList = $field['validator']; |
1608
|
|
|
} |
1609
|
|
|
} |
1610
|
|
|
} |
1611
|
|
|
|
1612
|
|
|
if($validatorList !== null) { |
1613
|
|
|
foreach($validatorList as $v) { |
1614
|
|
|
if (!$v->isValid()) { |
1615
|
|
|
$valid = false; |
1616
|
|
|
foreach($v->getErrors() as $error) { |
1617
|
|
|
$this->feedback->log('error', $error); |
1618
|
|
|
} |
1619
|
|
|
} |
1620
|
|
|
} |
1621
|
|
|
} |
1622
|
|
|
} |
1623
|
|
|
return $valid; |
1624
|
|
|
} |
1625
|
|
|
|
1626
|
|
|
function validateMetadata($label, &$md) { |
1627
|
|
|
$valid = false; |
1628
|
|
|
|
1629
|
|
|
$mdFactory = new Docman_MetadataFactory($this->groupId); |
1630
|
|
|
if($mdFactory->isValidLabel($label)) { |
1631
|
|
|
$_md =& $mdFactory->getFromLabel($label); |
1632
|
|
|
if($_md !== null |
1633
|
|
|
&& $_md->getGroupId() == $this->groupId) { |
1634
|
|
|
$valid = true; |
1635
|
|
|
$md = $_md; |
1636
|
|
|
} |
1637
|
|
|
} |
1638
|
|
|
|
1639
|
|
|
return $valid; |
1640
|
|
|
} |
1641
|
|
|
|
1642
|
|
|
/** |
1643
|
|
|
* Checks that the new property have a non-empty name, |
1644
|
|
|
* and also checks that the same name is not already taken by |
1645
|
|
|
* another property |
1646
|
|
|
*/ |
1647
|
|
|
private function validateNewMetadata($name) { |
1648
|
|
|
$name = trim($name); |
1649
|
|
|
if ($name == '') { |
1650
|
|
|
$valid = false; |
1651
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_name_missing')); |
1652
|
|
|
} else { |
1653
|
|
|
$mdFactory = new Docman_MetadataFactory($this->groupId); |
1654
|
|
|
|
1655
|
|
|
if($mdFactory->findByName($name)->count() == 0) { |
1656
|
|
|
$valid = true; |
1657
|
|
|
} else { |
1658
|
|
|
$valid = false; |
1659
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_name_exists', $name)); |
1660
|
|
|
} |
1661
|
|
|
} |
1662
|
|
|
|
1663
|
|
|
return $valid; |
1664
|
|
|
} |
1665
|
|
|
|
1666
|
|
|
/** |
1667
|
|
|
* Checks that the updating property have a non-empty name, |
1668
|
|
|
* and if the name have been changed, also checks that the same |
1669
|
|
|
* name is not already taken by another property |
1670
|
|
|
*/ |
1671
|
|
|
private function validateUpdateMetadata($name, $label) { |
1672
|
|
|
$name = trim($name); |
1673
|
|
|
if ($name == '') { |
1674
|
|
|
$valid = false; |
1675
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_name_missing')); |
1676
|
|
|
} else { |
1677
|
|
|
$mdFactory = new Docman_MetadataFactory($this->groupId); |
1678
|
|
|
|
1679
|
|
|
$md = $mdFactory->getFromLabel($label); |
1680
|
|
|
// name has changed |
1681
|
|
|
if ($md !== null && $md->getName() != $name) { |
1682
|
|
|
if($mdFactory->findByName($name)->count() == 0) { |
1683
|
|
|
$valid = true; |
1684
|
|
|
} else { |
1685
|
|
|
$valid = false; |
1686
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'admin_metadata_new_name_exists', $name)); |
1687
|
|
|
} |
1688
|
|
|
} else { |
1689
|
|
|
$valid = true; |
1690
|
|
|
} |
1691
|
|
|
} |
1692
|
|
|
|
1693
|
|
|
return $valid; |
1694
|
|
|
} |
1695
|
|
|
|
1696
|
|
|
function validateLove($loveId, $md, &$love) { |
1697
|
|
|
$valid = false; |
1698
|
|
|
|
1699
|
|
|
$loveFactory = new Docman_MetadataListOfValuesElementFactory($md->getId()); |
1700
|
|
|
$_love =& $loveFactory->getByElementId($loveId, $md->getLabel()); |
1701
|
|
|
if($_love !== null) { |
1702
|
|
|
// Still Need to verify that $love belong to $md |
1703
|
|
|
$valid = true; |
1704
|
|
|
$love = $_love; |
1705
|
|
|
} |
1706
|
|
|
|
1707
|
|
|
return $valid; |
1708
|
|
|
} |
1709
|
|
|
|
1710
|
|
|
function checkPasteIsAllowed($item, &$itemToPaste, &$mode) { |
1711
|
|
|
$isAllowed = false; |
1712
|
|
|
|
1713
|
|
|
$itemFactory =& $this->_getItemFactory(); |
1714
|
|
|
$user =& $this->getUser(); |
1715
|
|
|
|
1716
|
|
|
$type = $itemFactory->getItemTypeForItem($item); |
1717
|
|
|
if(PLUGIN_DOCMAN_ITEM_TYPE_FOLDER != $type) { |
1718
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_paste_in_document')); |
1719
|
|
|
} |
1720
|
|
|
elseif (!$this->userCanWrite($item->getId())) { |
1721
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); |
1722
|
|
|
} |
1723
|
|
|
else { |
1724
|
|
|
$copiedItemId = $itemFactory->getCopyPreference($user); |
1725
|
|
|
$cutItemId = $itemFactory->getCutPreference($user, $item->getGroupId()); |
1726
|
|
|
$itemToPaste = null; |
1727
|
|
|
|
1728
|
|
|
if ($copiedItemId !== false && $cutItemId === false) { |
1729
|
|
|
$itemToPaste = $itemFactory->getItemFromDb($copiedItemId); |
1730
|
|
|
$mode = 'copy'; |
1731
|
|
|
} |
1732
|
|
|
elseif ($item->getId() == $cutItemId) { |
1733
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_paste_same_Item')); |
1734
|
|
|
return false; |
1735
|
|
|
} |
1736
|
|
|
elseif ($copiedItemId === false && $cutItemId !== false) { |
1737
|
|
|
if ($itemFactory->isInSubTree($item->getId(), $cutItemId)) { |
1738
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_cut_paste_in_subItem')); |
1739
|
|
|
return false; |
1740
|
|
|
} |
1741
|
|
|
$itemToPaste = $itemFactory->getItemFromDb($cutItemId); |
1742
|
|
|
$mode = 'cut'; |
1743
|
|
|
} |
1744
|
|
|
else { |
1745
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_paste_no_valid_item')); |
1746
|
|
|
return false; |
1747
|
|
|
} |
1748
|
|
|
|
1749
|
|
|
if($itemToPaste == null) { |
1750
|
|
|
$this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_paste_no_valid_item')); |
1751
|
|
|
} |
1752
|
|
|
else { |
1753
|
|
|
$isAllowed = true; |
1754
|
|
|
} |
1755
|
|
|
} |
1756
|
|
|
|
1757
|
|
|
return $isAllowed; |
1758
|
|
|
} |
1759
|
|
|
|
1760
|
|
|
function actionsManagement() { |
1761
|
|
|
// Redefine actions classes names building. |
1762
|
|
|
$className = get_class($this); |
1763
|
|
|
$class = substr($className, 0, -(strlen("Controller"))) . 'Actions'; |
1764
|
|
|
require_once($class.'.class.php'); |
1765
|
|
|
$wa = new $class($this, $this->gid); |
1766
|
|
|
$wa->process($this->action, $this->_actionParams); |
1767
|
|
|
} |
1768
|
|
|
|
1769
|
|
|
function viewsManagement() { |
1770
|
|
|
if ($this->view !== null) { |
1771
|
|
|
$className = $this->_includeView(); |
1772
|
|
|
if (class_exists($className)) { |
1773
|
|
|
$wv = new $className($this); |
1774
|
|
|
return $wv->display($this->_viewParams); |
1775
|
|
|
} else { |
1776
|
|
|
die($className .' does not exist.'); |
|
|
|
|
1777
|
|
|
} |
1778
|
|
|
} |
1779
|
|
|
} |
1780
|
|
|
function _count(&$item, &$hierarchy, $go = false) { |
1781
|
|
|
$nb = $go ? 1 : 0; |
1782
|
|
|
if (is_a($hierarchy, 'Docman_Folder')) { |
1783
|
|
|
$list =& $hierarchy->getAllItems(); |
1784
|
|
|
$iter =& $list->iterator(); |
1785
|
|
|
while($iter->valid()) { |
1786
|
|
|
$o =& $iter->current(); |
1787
|
|
|
$n = $this->_count($item, $o, $go ? $go : $o->getId() == $item->getId()); |
1788
|
|
|
if ($n) { |
1789
|
|
|
$nb += $n; |
1790
|
|
|
} |
1791
|
|
|
$iter->next(); |
1792
|
|
|
} |
1793
|
|
|
} |
1794
|
|
|
return $nb; |
1795
|
|
|
} |
1796
|
|
|
|
1797
|
|
|
function &getItemHierarchy($rootItem) { |
1798
|
|
|
if(!isset($this->hierarchy[$rootItem->getId()])) { |
1799
|
|
|
$itemFactory = new Docman_ItemFactory($rootItem->getGroupId()); |
1800
|
|
|
$this->hierarchy[$rootItem->getId()] =& $itemFactory->getItemTree($rootItem, $this->getUser(), false, true); |
1801
|
|
|
} |
1802
|
|
|
return $this->hierarchy[$rootItem->getId()]; |
1803
|
|
|
} |
1804
|
|
|
|
1805
|
|
|
/** |
1806
|
|
|
* @return Project |
1807
|
|
|
*/ |
1808
|
|
|
private function getProject() { |
1809
|
|
|
return ProjectManager::instance()->getProject($this->getGroupId()); |
1810
|
|
|
} |
1811
|
|
|
|
1812
|
|
|
private function getMailBuilder() { |
1813
|
|
|
return new MailBuilder(TemplateRendererFactory::build()); |
1814
|
|
|
} |
1815
|
|
|
} |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.