function _toolbar($params) { // No toolbar in printer version if (isset($params['pv']) && $params['pv'] > 0) { return; } $tools = array(); $this->_addDocmanTool($params, $tools); $dPm =& Docman_PermissionsManager::instance($params['group_id']); $user =& $this->_controller->getUser(); $oneFolderWritable = $dPm->oneFolderIsWritable($user); if ($oneFolderWritable) { $url_params = array('action' => 'newGlobalDocument'); if (isset($params['item'])) { $url_params['id'] = $params['item']->accept(new Docman_View_ToolbarNewDocumentVisitor()); } $tools[] = '<b><a href="' . $this->buildUrl($params['default_url'], $url_params) . '">' . $GLOBALS['Language']->getText('plugin_docman', 'new_document') . '</a></b>'; if ($this->_controller->userCanAdmin()) { $tools[] = '<b><a href="' . $params['default_url'] . '&action=admin">' . $GLOBALS['Language']->getText('plugin_docman', 'toolbar_admin') . '</a></b>'; } } $tools[] = help_button('DocumentManagerPlugin.html', false, $GLOBALS['Language']->getText('global', 'help')); echo implode(' | ', $tools); echo "\n"; }
function Docman_View_GetMenuItemsVisitor(&$user, $groupId) { $this->dPm =& Docman_PermissionsManager::instance($groupId); $this->user =& $user; $this->if =& Docman_ItemFactory::instance($groupId); $this->actions = array(); }
function _content($params) { $item = $params['item']; $dPm =& Docman_PermissionsManager::instance($item->getGroupId()); $html = ''; $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'view_empty_emptydoc') . '</h3>'; $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docman', 'view_empty_docisempty') . '</p>'; if ($dPm->userCanWrite($params['user'], $item->getId())) { $upurl = $params['default_url'] . '&action=action_update&id=' . $item->getId(); $html .= '<p><a href="' . $upurl . '">' . $GLOBALS['Language']->getText('plugin_docman', 'view_empty_update') . '</a></p>'; } $html .= '<h3>' . $GLOBALS['Language']->getText('plugin_docman', 'view_empty_docmd') . '</h3>'; $html .= '<table>'; $html .= '<tr><td class="label">'; $get_fields = new Docman_View_GetFieldsVisitor(); $fields = $item->accept($get_fields, $params); foreach ($fields as $field) { $html .= '<tr>'; $html .= '<td class="label">' . $field->getLabel() . '</td>'; $html .= '<td class="value">' . $field->getValue() . '</span></td>'; $html .= '</tr>'; } $html .= '</table>'; if ($dPm->userCanWrite($params['user'], $item->getId())) { $editurl = $params['default_url'] . '&action=edit&id=' . $item->getId(); $html .= '<p><a href="' . $editurl . '">' . $GLOBALS['Language']->getText('plugin_docman', 'details_properties_edit') . '</a></p>'; } print $html; }
function getTable($params) { $this->defaultUrl = $params['default_url']; $content = ''; $content .= html_build_list_table_top(array($GLOBALS['Language']->getText('plugin_docman', 'view_documenttable_title'), $GLOBALS['Language']->getText('plugin_docman', 'view_documenttable_location'), $GLOBALS['Language']->getText('plugin_docman', 'admin_lock_infos_who'), $GLOBALS['Language']->getText('plugin_docman', 'admin_lock_infos_when'))); // Get list of all locked documents in the project. $dPM = Docman_PermissionsManager::instance($params['group_id']); $lockInfos = $dPM->getLockFactory()->getProjectLockInfos($params['group_id']); $uH = UserHelper::instance(); $hp = Codendi_HTMLPurifier::instance(); require_once dirname(__FILE__) . '/../Docman_ItemFactory.class.php'; $dIF = new Docman_ItemFactory($params['group_id']); $altRowClass = 0; foreach ($lockInfos as $row) { $trclass = html_get_alt_row_color($altRowClass++); $item = $dIF->getItemFromDb($row['item_id']); $parent = $dIF->getItemFromDb($item->getParentId()); $content .= '<tr class="' . $trclass . '">'; $content .= '<td>' . '<a href="/plugins/docman/?group_id=' . $params['group_id'] . '&action=details&id=' . $item->getId() . '">' . $item->getTitle() . '</a></td>'; $content .= '<td>'; if ($dIF->isRoot($parent)) { $content .= '</td>'; } else { $content .= '<a href="' . $this->defaultUrl . '&action=show&id=' . $parent->getId() . '">' . $parent->getTitle() . '</a></td>'; } $content .= '<td>' . $hp->purify($uH->getDisplayNameFromUserId($row['user_id'])) . '</td>'; $content .= '<td>' . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $row['lock_date']) . '</td>'; $content .= '</tr>'; } $content .= '</table>'; return $content; }
/** * Returns an array containing all the permissions for the specified item. * The ugroups that have no permission defined in the request take the permission of the parent folder. */ function _get_permissions_as_array($group_id, $item_id, $permissions) { $permissions_array = array(); $perms = array('PLUGIN_DOCMAN_READ', 'PLUGIN_DOCMAN_WRITE', 'PLUGIN_DOCMAN_MANAGE'); // Get the ugroups of the parent $ugroups = permission_get_ugroups_permissions($group_id, $item_id, $perms, false); // Initialize the ugroup permissions to the same values as the parent folder foreach ($ugroups as $ugroup) { $ugroup_id = $ugroup['ugroup']['id']; $permissions_array[$ugroup_id] = 100; foreach ($perms as $perm) { if (isset($ugroup['permissions'][$perm])) { $permissions_array[$ugroup_id] = Docman_PermissionsManager::getDefinitionIndexForPermission($perm); } } } // Set the SOAP-provided permissions foreach ($permissions as $index => $permission) { $ugroup_id = $permission->ugroup_id; if (isset($permissions_array[$ugroup_id])) { $permissions_array[$ugroup_id] = Docman_PermissionsManager::getDefinitionIndexForPermission($permission->type); } } return $permissions_array; }
function Docman_SubItemsWritableVisitor($groupId, $user) { $this->dpm =& Docman_PermissionsManager::instance($groupId); $this->user = $user; $this->docIdList = array(); $this->fldIdList = array(); $this->docCounter = 0; $this->fldCounter = 0; }
function _getReleaseLock() { $content = ''; $dPm = Docman_PermissionsManager::instance($this->item->getGroupId()); if ($dPm->getLockFactory()->itemIsLocked($this->item)) { $content .= '<tr style="vertical-align:top;">'; $content .= '<td><label>' . $GLOBALS['Language']->getText('plugin_docman', 'details_actions_update_lock') . '</label></td>'; $content .= '<td><input type="checkbox" name="lock_document" value="lock" /></td>'; $content .= '</tr>'; } return $content; }
function _subItemsAreWritable() { if ($this->subItemsWritable === null) { $dPm =& Docman_PermissionsManager::instance($this->item->getGroupId()); $this->subItemsWritable = $dPm->currentUserCanWriteSubItems($this->item->getId()); // Cache some info. $subItemsWritableVisitor =& $dPm->getSubItemsWritableVisitor(); $this->nbDocsImpacted = $subItemsWritableVisitor->getDocumentCounter(); // Do not count the first folder which is the parent one. $this->nbFoldersImpacted = $subItemsWritableVisitor->getFolderCounter() - 1; } return $this->subItemsWritable; }
function checkMdDifferences(&$mdDiffers) { $html = ''; $mdCmp = new Docman_MetadataComparator($this->srcGo->getGroupId(), $this->dstGo->getGroupId(), $this->_controller->getThemePath()); $cmpTable = $mdCmp->getMetadataCompareTable($sthToImport); if ($sthToImport) { $html .= '<h2>' . $GLOBALS['Language']->getText('plugin_docman', 'details_paste_mddiff_title') . '</h2>'; $dPm =& Docman_PermissionsManager::instance($this->dstGo->getGroupId()); if ($dPm->currentUserCanAdmin()) { $mdDiffers = 'admin'; $html .= $cmpTable; } else { $mdDiffers = 'user'; $docmanIcons = $this->_getDocmanIcons(); $html .= $GLOBALS['Language']->getText('plugin_docman', 'details_paste_mddiff_noadmin', array($this->srcGo->getPublicName(), $this->dstGo->getPublicName(), $docmanIcons->getThemeIcon('warning.png'))); } } return $html; }
function getContent() { $html = ''; $request = HTTPRequest::instance(); $um = UserManager::instance(); $user = $um->getCurrentUser(); $vFunc = new Valid_WhiteList('docman_func', array('show_docman')); $vFunc->required(); if ($request->valid($vFunc)) { $func = $request->get('docman_func'); } else { $func = ''; } $vDocmanId = new Valid_UInt('docman_id'); $vDocmanId->required(); if ($request->valid($vDocmanId)) { $docman_id = $request->get('docman_id'); } else { $docman_id = ''; } $html .= '<form method="post" action="?">'; $html .= '<label>' . $GLOBALS['Language']->getText('plugin_docman', 'widget_my_docman_search_label') . '</label>'; $html .= '<input type="hidden" name="docman_func" value="show_docman" />'; $html .= '<input type="text" name="docman_id" value="' . $docman_id . '" id="docman_id" />'; $html .= ' '; $html .= '<input type="submit" value="' . $GLOBALS['Language']->getText('plugin_docman', 'widget_my_docman_search_btn') . '"/>'; $html .= '</form>'; if ($func == 'show_docman' && $docman_id) { $res = $this->returnAllowedGroupId($docman_id, $user); if ($res) { $dPm = Docman_PermissionsManager::instance($res['group_id']); $itemPerm = $dPm->userCanAccess($user, $docman_id); if ($itemPerm) { $html .= '<p><a href="/plugins/docman/?group_id=' . $res['group_id'] . '&action=details&id=' . $docman_id . '§ion=properties">Show "' . $res['title'] . '" Properties</a></p>'; return $html; } } $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docman', 'perm_denied') . '</p>'; } return $html; }
/** * Show list of people monitoring the document directly or indirectly by monitoring one of the parents and its subitems * * @param Integer $itemId Id of the document * * @return String */ function displayListeningUsers($itemId) { $dpm = Docman_PermissionsManager::instance($this->item->getGroupId()); $userHelper = new UserHelper(); $um = UserManager::instance(); $content = ''; if ($dpm->userCanManage($um->getCurrentUser(), $itemId)) { $listeners = $this->notificationsManager->getListeningUsers($this->item); if (!empty($listeners)) { $content .= '<fieldset><legend>' . $GLOBALS['Language']->getText('plugin_docman', 'details_listeners') . '</legend>'; $content .= '<form name="remove_monitoring" method="POST" action="">'; $content .= '<input type="hidden" name="action" value="remove_monitoring" />'; $content .= '<table><tr><td>'; $content .= html_build_list_table_top(array($GLOBALS['Language']->getText('people_viewprofile', 'user_name'), $GLOBALS['Language']->getText('plugin_docman', 'details_notifications_monitored_doc'), $GLOBALS['Language']->getText('docman_doc_utils', 'delete_ask')), false, false, false); $rowBgColor = 0; $hp = Codendi_HTMLPurifier::instance(); foreach ($listeners as $userId => $item) { $content .= '<tr class="' . html_get_alt_row_color(++$rowBgColor) . '">'; $user = $um->getUserById($userId); $content .= '<td>' . $userHelper->getDisplayName($user->getName(), $user->getRealName()) . '</td>'; $content .= '<td>' . $item->getTitle() . '</td><td>'; if ($this->item == $item) { $content .= '<input type="checkbox" value="' . $userId . '" name="listeners_to_delete[]">'; } else { $content .= '<input type="checkbox" value="' . $userId . '" name="listeners_to_delete[]" disabled="disabled">'; } $content .= '</td></tr>'; } // TODO : ask user if he wants or not to notify the users he remove // TODO : We may ask him also if his name will appear as the guilty one or not $content .= '<td colspan="2"><input type="submit" value="' . $GLOBALS['Language']->getText('plugin_docman', 'action_delete') . '"></td></tr>'; $content .= '</tbody></table></form>'; $content .= '</td><td><div class="docman_help">' . $GLOBALS['Language']->getText('plugin_docman', 'details_notifications_help') . '</div></td></tr>'; } $content .= $this->addListeningUser($itemId); $content .= '</table></fieldset>'; } return $content; }
function getDropDownWidget($parentItem) { $itemFactory =& Docman_ItemFactory::instance($parentItem->getGroupId()); $brotherIter = $itemFactory->getChildrenFromParent($parentItem); $vals = array('beginning', 'end', '--'); $texts = array($GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_beg'), $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_end'), '----'); $i = 3; $pm =& Docman_PermissionsManager::instance($parentItem->getGroupId()); $um =& UserManager::instance(); $user =& $um->getCurrentUser(); $hp = Codendi_HTMLPurifier::instance(); $brotherIter->rewind(); while ($brotherIter->valid()) { $item = $brotherIter->current(); if ($pm->userCanWrite($user, $item->getId())) { $vals[$i] = $item->getRank() + 1; $texts[$i] = $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_after') . ' ' . $hp->purify($item->getTitle(), CODENDI_PURIFIER_CONVERT_HTML); $i++; } $brotherIter->next(); } // Cannot use html_build_select_box_from_arrays because of to lasy == operator // In this case because of cast string values are converted to 0 on cmp. So if // there is a rank == 0 ... so bad :/ $html = ''; $html = $GLOBALS['Language']->getText('plugin_docman', 'view_itemrank_position') . ' '; $html .= '<select name="' . $this->dropDownName . '">' . "\n"; $maxOpts = count($vals); for ($i = 0; $i < $maxOpts; $i++) { $selected = ''; if ($vals[$i] === $this->selectedValue) { $selected = ' selected="selected"'; } $html .= '<option value="' . $vals[$i] . '"' . $selected . '>' . $texts[$i] . '</option>' . "\n"; } $html .= '</select>'; return $html; }
/** * Wrapper for Docman_PermissionsManager class * @param $groupId * @return Docman_PermissionsManager */ function getDocman_PermissionsManager($groupId) { include_once dirname(__FILE__) . '/../../docman/include/Docman_PermissionsManager.class.php'; return Docman_PermissionsManager::instance($groupId); }
/** * Wrapper for Docman_PermissionsManager * * @param Integer $groupId * * @return Docman_PermissionsManager */ function getDocman_PermissionsManager($groupId) { return Docman_PermissionsManager::instance($groupId); }
function _dispatch($view, $item, $root, $get_show_view) { $item_factory =& $this->_getItemFactory(); $user =& $this->getUser(); $dpm =& Docman_PermissionsManager::instance($this->getGroupId()); switch ($view) { case 'show': if ($item->isObsolete()) { if (!$this->userCanAdmin($item->getId())) { // redirect to details view $this->view = 'Details'; break; } } $this->view = $item->accept($get_show_view, $this->request->get('report')); break; case 'expandFolder': $this->action = 'expandFolder'; if ($this->request->get('view') == 'ulsubfolder') { $this->view = 'RawTree'; } else { $this->_viewParams['item'] =& $root; $this->view = 'Tree'; } break; case 'getRootFolder': $this->_viewParams['action_result'] = $root->getId(); $this->_setView('getRootFolder'); break; case 'collapseFolder': $this->action = 'collapseFolder'; $this->_viewParams['item'] =& $root; $this->view = 'Tree'; break; case 'admin_set_permissions': $this->action = $view; $this->view = 'Admin_Permissions'; break; case 'admin_change_view': $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'admin_view', 'id' => $item->getParentId()); $this->view = 'RedirectAfterCrud'; break; case 'admin': case 'details': $this->view = ucfirst($view); break; case 'admin_view': $this->view = 'Admin_View'; break; case 'admin_permissions': $this->view = 'Admin_Permissions'; break; case 'admin_metadata': $this->view = 'Admin_Metadata'; $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); $mdIter =& $mdFactory->getMetadataForGroup(); $this->_viewParams['mdIter'] =& $mdIter; break; case 'admin_md_details': // Sanitize $_mdLabel = $this->request->get('md'); $md = null; $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); $valid = $this->validateMetadata($_mdLabel, $md); if (!$valid) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_invalid_md')); $this->view = 'RedirectAfterCrud'; $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } else { $this->view = 'Admin_MetadataDetails'; $mdFactory->appendMetadataValueList($md, false); $this->_viewParams['md'] =& $md; } break; case 'admin_md_details_update': $_name = trim($this->request->get('name')); $_label = $this->request->get('label'); $mdFactory = $this->_getMetadataFactory($this->_viewParams['group_id']); if ($mdFactory->isValidLabel($_label)) { $this->_viewParams['default_url_params'] = array('action' => 'admin_md_details', 'md' => $_label); if ($mdFactory->isHardCodedMetadata($_label) || $this->validateUpdateMetadata($_name, $_label)) { $this->action = $view; } } else { $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } $this->view = 'RedirectAfterCrud'; break; case 'admin_create_metadata': $_name = trim($this->request->get('name')); $valid = $this->validateNewMetadata($_name); if ($valid) { $this->action = $view; } $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); $this->view = 'RedirectAfterCrud'; break; case 'admin_delete_metadata': $valid = false; // md // Sanitize $_mdLabel = $this->request->get('md'); // Valid $logmsg = ''; $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); $md = null; $vld = $this->validateMetadata($_mdLabel, $md); if ($vld) { if (!$mdFactory->isHardCodedMetadata($md->getLabel())) { $valid = true; } else { $logmsg = $GLOBALS['Language']->getText('plugin_docman', 'error_cannot_delete_hc_md'); } } else { $logmsg = $GLOBALS['Language']->getText('plugin_docman', 'error_invalid_md'); } if (!$valid) { if ($logmsg != '') { $this->feedback->log('error', $logmsg); } $this->view = 'RedirectAfterCrud'; $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } else { $this->action = $view; $this->_actionParams['md'] = $md; } break; case 'admin_create_love': $mdFactory = $this->_getMetadataFactory($this->_viewParams['group_id']); if ($mdFactory->isValidLabel($this->request->get('md'))) { $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'admin_md_details', 'md' => $this->request->get('md')); } else { $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } $this->view = 'RedirectAfterCrud'; break; case 'admin_delete_love': $mdFactory = $this->_getMetadataFactory($this->_viewParams['group_id']); if ($mdFactory->isValidLabel($this->request->get('md'))) { $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'admin_md_details', 'md' => $this->request->get('md')); } else { $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } $this->view = 'RedirectAfterCrud'; break; case 'admin_display_love': $valid = false; // Required params: // md (string [a-z_]+) // loveid (int) // Sanitize $_mdLabel = $this->request->get('md'); $_loveId = (int) $this->request->get('loveid'); // Valid $md = null; $love = null; $this->validateMetadata($_mdLabel, $md); if ($md !== null && $md->getLabel() !== 'status') { $valid = $this->validateLove($_loveId, $md, $love); } if (!$valid) { $this->view = 'RedirectAfterCrud'; $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } else { $mdFactory = new Docman_MetadataFactory($this->groupId); $mdFactory->appendMetadataValueList($md, false); $this->view = 'Admin_MetadataDetailsUpdateLove'; $this->_viewParams['md'] = $md; $this->_viewParams['love'] = $love; } break; case 'admin_update_love': $valid = false; // Required params: // md (string [a-z_]+) // loveid (int) // // rank (beg, end, [0-9]+) // name // descr // Sanitize /// @todo sanitize md, rank, name, descr $_mdLabel = $this->request->get('md'); $_loveId = (int) $this->request->get('loveid'); $_rank = $this->request->get('rank'); $_name = $this->request->get('name'); $_descr = $this->request->get('descr'); // Valid $md = null; $love = null; $this->validateMetadata($_mdLabel, $md); if ($md !== null && $md->getLabel() !== 'status') { $valid = $this->validateLove($_loveId, $md, $love); } if (!$valid) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_md_or_love')); $this->view = 'RedirectAfterCrud'; $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } else { // Set parameters $love->setRank($_rank); $love->setName($_name); $love->setDescription($_descr); // define action $this->action = $view; $this->_actionParams['md'] = $md; $this->_actionParams['love'] = $love; } break; case 'admin_import_metadata_check': $ok = false; if ($this->request->existAndNonEmpty('plugin_docman_metadata_import_group')) { $pm = ProjectManager::instance(); $srcGroup = $pm->getProjectFromAutocompleter($this->request->get('plugin_docman_metadata_import_group')); if ($srcGroup && !$srcGroup->isError()) { $this->_viewParams['sSrcGroupId'] = $srcGroup->getGroupId(); $this->view = 'Admin_MetadataImport'; $ok = true; } } if (!$ok) { $this->view = 'RedirectAfterCrud'; $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); } break; case 'admin_import_metadata': if ($this->request->existAndNonEmpty('confirm')) { if ($this->request->existAndNonEmpty('plugin_docman_metadata_import_group')) { $pm = ProjectManager::instance(); $srcGroup = $pm->getProjectFromAutocompleter($this->request->get('plugin_docman_metadata_import_group')); $srcGroupId = $srcGroup->getGroupId(); $this->_actionParams['sSrcGroupId'] = $srcGroupId; $this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; $this->action = $view; } else { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'missing_param')); $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'operation_canceled')); } } else { $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'operation_canceled')); } $this->view = 'RedirectAfterCrud'; $this->_viewParams['default_url_params'] = array('action' => 'admin_metadata'); break; case 'admin_obsolete': $this->view = 'Admin_Obsolete'; break; case 'admin_lock_infos': $this->view = 'Admin_LockInfos'; break; case 'move': if (!$this->userCanWrite($item->getId()) || !$this->userCanWrite($item->getParentId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_move')); $this->view = 'Details'; } else { if ($this->request->exist('quick_move')) { $this->action = 'move'; $this->view = null; } else { $this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); $this->view = ucfirst($view); } } break; case 'newGlobalDocument': if ($dpm->oneFolderIsWritable($user)) { $this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); $this->view = 'New_FolderSelection'; } else { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_create')); $this->view = $item->accept($get_show_view, $this->request->get('report')); } break; case 'newDocument': case 'newFolder': if ($this->request->exist('cancel')) { $this->_set_redirectView(); } else { if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_create')); $this->view = 'Details'; } else { //$this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); $this->_viewParams['ordering'] = $this->request->get('ordering'); if ($this->request->get('item_type') == PLUGIN_DOCMAN_ITEM_TYPE_FOLDER) { $view = 'newFolder'; } $this->view = ucfirst($view); } } break; case 'monitor': if ($this->request->exist('monitor')) { $this->_actionParams['monitor'] = $this->request->get('monitor'); if ($this->request->exist('cascade')) { $this->_actionParams['cascade'] = $this->request->get('cascade'); } $this->_actionParams['item'] =& $item; $this->action = 'monitor'; } $this->_setView('Details'); break; case 'remove_monitoring': $this->_actionParams['listeners_to_delete'] = array(); if ($this->userCanManage($item->getId())) { if ($this->request->exist('listeners_to_delete')) { $um = UserManager::instance(); $vUserId = new Valid_UInt('listeners_to_delete'); if ($this->request->validArray($vUserId)) { $userIds = $this->request->get('listeners_to_delete'); $users = array(); foreach ($userIds as $userId) { $users[] = $um->getUserById($userId); } $this->_actionParams['listeners_to_delete'] = $users; $this->_actionParams['item'] = $item; } } $this->action = 'remove_monitoring'; $this->_setView('Details'); } else { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'notifications_permission_denied')); $this->_setView('Details'); } break; case 'add_monitoring': $this->_actionParams['listeners_to_add'] = array(); $this->_actionParams['invalid_users'] = false; if ($this->userCanManage($item->getId())) { if ($this->request->exist('listeners_to_add')) { $um = UserManager::instance(); $vUser = new Valid_Text('listeners_to_add'); if ($this->request->valid($vUser)) { $usernames = array_map('trim', preg_split('/[,;]/', $this->request->get('listeners_to_add'))); $users = array(); $vUserName = new Valid_String(); $vUserName->required(); foreach ($usernames as $username) { if ($vUserName->validate($username) && ($user = $um->findUser($username))) { $users[] = $user; } else { $this->_actionParams['invalid_users'] = true; } } if ($this->request->exist('monitor_cascade')) { $this->_actionParams['monitor_cascade'] = $this->request->get('monitor_cascade'); } $this->_actionParams['listeners_to_add'] = $users; $this->_actionParams['item'] = $item; } } $this->action = 'add_monitoring'; $this->_setView('Details'); } else { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'notifications_permission_denied')); $this->_setView('Details'); } break; case 'move_here': if (!$this->request->exist('item_to_move')) { $this->feedback->log('error', 'Missing parameter.'); $this->view = 'DocmanError'; } else { $item_to_move =& $item_factory->getItemFromDb($this->request->get('item_to_move')); $this->view = null; if ($this->request->exist('confirm')) { if (!$item_to_move || !($this->userCanWrite($item->getId()) && $this->userCanWrite($item_to_move->getId()) && $this->userCanWrite($item_to_move->getParentId()))) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_move')); $this->_set_moveView_errorPerms(); } else { $this->action = 'move'; } } if (!$this->view) { $this->_set_redirectView(); } } break; case 'permissions': if (!$this->userCanManage($item->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_perms')); $this->view = 'Details'; } else { $this->action = 'permissions'; $this->view = 'Details'; } break; case 'confirmDelete': if (!$this->userCanWrite($item->getId()) || !$this->userCanWrite($item->getParentId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_delete')); $this->view = 'Details'; } else { $this->view = 'Delete'; } break; case 'action_new_version': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); $this->view = 'Details'; } else { $this->view = 'NewVersion'; } break; case 'action_update': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); $this->view = 'Details'; } else { $this->view = 'Update'; } break; case 'action_copy': //@XSS: validate action against a regexp. $_action = $this->request->get('orig_action'); $_id = (int) $this->request->get('orig_id'); $this->_actionParams['item'] = $item; $this->action = $view; if (!$this->request->exist('ajax_copy')) { $this->_viewParams['default_url_params'] = array('action' => $_action, 'id' => $_id); $this->view = 'RedirectAfterCrud'; } break; case 'action_cut': $_action = $this->request->get('orig_action'); $_id = (int) $this->request->get('orig_id'); $this->_actionParams['item'] = $item; $this->action = $view; if (!$this->request->exist('ajax_cut')) { $this->_viewParams['default_url_params'] = array('action' => $_action, 'id' => $_id); $this->view = 'RedirectAfterCrud'; } break; case 'action_paste': $itemToPaste = null; $mode = null; $allowed = $this->checkPasteIsAllowed($item, $itemToPaste, $mode); if (!$allowed) { $this->view = 'Details'; } else { $this->_viewParams['itemToPaste'] = $itemToPaste; $this->_viewParams['srcMode'] = $mode; $this->view = 'Paste'; } break; case 'paste_cancel': // intend to be only called through ajax call $item_factory->delCopyPreference(); $item_factory->delCutPreference(); break; case 'paste': if ($this->request->exist('cancel')) { $this->_viewParams['default_url_params'] = array('action' => 'show'); $this->view = 'RedirectAfterCrud'; } else { $itemToPaste = null; $mode = null; $allowed = $this->checkPasteIsAllowed($item, $itemToPaste, $mode); if (!$allowed) { $this->view = 'Details'; } else { $this->_viewParams['importMd'] = false; if ($this->userCanAdmin()) { if ($this->request->exist('import_md') && $this->request->get('import_md') == '1') { $this->_viewParams['importMd'] = true; } } $this->_viewParams['item'] = $item; $this->_viewParams['rank'] = $this->request->get('rank'); $this->_viewParams['itemToPaste'] = $itemToPaste; $this->_viewParams['srcMode'] = $mode; /*$this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'show', 'id' => $item->getId()); $this->view = 'RedirectAfterCrud';*/ $this->_viewParams['item'] = $item; $this->_viewParams['rank'] = $this->request->get('rank'); $this->_viewParams['itemToPaste'] = $itemToPaste; $this->_viewParams['srcMode'] = $mode; $this->view = 'PasteInProgress'; } } break; case 'approval_create': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { $this->view = 'ApprovalCreate'; } break; case 'approval_delete': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { if ($this->request->exist('confirm')) { $this->action = $view; $this->_actionParams['item'] = $item; // Version $vVersion = new Valid_UInt('version'); $vVersion->required(); if ($this->request->valid($vVersion)) { $this->_actionParams['version'] = $this->request->get('version'); } else { $this->_actionParams['version'] = null; } } $this->_viewParams['default_url_params'] = array('action' => 'details', 'section' => 'approval', 'id' => $item->getId()); $this->view = 'RedirectAfterCrud'; } break; case 'approval_update': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { $this->_actionParams['item'] = $item; // Settings $this->_actionParams['status'] = (int) $this->request->get('status'); $this->_actionParams['description'] = $this->request->get('description'); $this->_actionParams['notification'] = (int) $this->request->get('notification'); $this->_actionParams['reminder'] = $this->request->get('reminder'); $this->_actionParams['occurence'] = (int) $this->request->get('occurence'); $this->_actionParams['period'] = (int) $this->request->get('period'); // Users $this->_actionParams['user_list'] = $this->request->get('user_list'); $this->_actionParams['ugroup_list'] = null; if (is_array($this->request->get('ugroup_list'))) { $this->_actionParams['ugroup_list'] = array_map('intval', $this->request->get('ugroup_list')); } // Selected users $this->_actionParams['sel_user'] = null; if (is_array($this->request->get('sel_user'))) { $this->_actionParams['sel_user'] = array_map('intval', $this->request->get('sel_user')); } $allowedAct = array('100', 'mail', 'del'); $this->_actionParams['sel_user_act'] = null; if (in_array($this->request->get('sel_user_act'), $allowedAct)) { $this->_actionParams['sel_user_act'] = $this->request->get('sel_user_act'); } // Resend $this->_actionParams['resend_notif'] = false; if ($this->request->get('resend_notif') == 'yes') { $this->_actionParams['resend_notif'] = true; } // Version $vVersion = new Valid_UInt('version'); $vVersion->required(); if ($this->request->valid($vVersion)) { $this->_actionParams['version'] = $this->request->get('version'); } else { $this->_actionParams['version'] = null; } // Import $vImport = new Valid_WhiteList('app_table_import', array('copy', 'reset', 'empty')); $vImport->required(); $this->_actionParams['import'] = $this->request->getValidated('app_table_import', $vImport, false); // Owner $vOwner = new Valid_String('table_owner'); $vOwner->required(); $this->_actionParams['table_owner'] = $this->request->getValidated('table_owner', $vOwner, false); // // Special handeling of table deletion if ($this->_actionParams['status'] == PLUGIN_DOCMAN_APPROVAL_TABLE_DELETED) { $this->_viewParams['default_url_params'] = array('action' => 'approval_create', 'delete' => 'confirm', 'id' => $item->getId()); } else { // Action! $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'approval_create', 'id' => $item->getId()); } if ($this->_actionParams['version'] !== null) { $this->_viewParams['default_url_params']['version'] = $this->_actionParams['version']; } $this->view = 'RedirectAfterCrud'; } break; case 'approval_upd_user': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { $this->_actionParams['item'] = $item; $this->_actionParams['user_id'] = (int) $this->request->get('user_id'); $this->_actionParams['rank'] = $this->request->get('rank'); $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'approval_create', 'id' => $item->getId()); $this->view = 'RedirectAfterCrud'; } break; case 'approval_del_user': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { $this->_actionParams['item'] = $item; $this->_actionParams['user_id'] = (int) $this->request->get('user_id'); $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'approval_create', 'id' => $item->getId()); $this->view = 'RedirectAfterCrud'; } break; case 'approval_user_commit': $atf =& Docman_ApprovalTableFactory::getFromItem($item); $table = $atf->getTable(); $atrf =& new Docman_ApprovalTableReviewerFactory($table, $item); if (!$this->userCanRead($item->getId()) || !$atrf->isReviewer($user->getId()) || !$table->isEnabled()) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { $this->_actionParams['item'] = $item; $svState = 0; $sState = (int) $this->request->get('state'); if ($sState >= 0 && $sState < 5) { $svState = $sState; } $this->_actionParams['svState'] = $svState; $this->_actionParams['sVersion'] = null; if ($this->request->exist('version')) { $sVersion = (int) $this->request->get('version'); switch ($item_factory->getItemTypeForItem($item)) { case PLUGIN_DOCMAN_ITEM_TYPE_WIKI: if ($sVersion <= 0) { $sVersion = null; } case PLUGIN_DOCMAN_ITEM_TYPE_FILE: case PLUGIN_DOCMAN_ITEM_TYPE_EMBEDDEDFILE: // assume ok: do nothing. break; default: $sVersion = null; } $this->_actionParams['sVersion'] = $sVersion; } $this->_actionParams['usComment'] = $this->request->get('comment'); $this->_actionParams['monitor'] = (int) $this->request->get('monitor'); $this->action = $view; $this->_viewParams['default_url_params'] = array('action' => 'details', 'section' => 'approval', 'id' => $item->getId()); $this->view = 'RedirectAfterCrud'; } break; case 'approval_notif_resend': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $this->txt('error_perms_edit')); $this->view = 'Details'; } else { $this->action = $view; $this->_actionParams['item'] = $item; $this->_viewParams['default_url_params'] = array('action' => 'approval_create', 'id' => $item->getId()); $this->view = 'RedirectAfterCrud'; } break; case 'edit': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); $this->view = 'Details'; } else { $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); $mdFactory->appendAllListOfValuesToItem($item); $this->view = 'Edit'; } break; case 'delete': if (!($this->userCanWrite($item->getId()) && $this->userCanWrite($item->getParentId()))) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_delete')); $this->_set_deleteView_errorPerms(); } else { if ($this->request->exist('confirm')) { $this->action = $view; $this->_set_redirectView(); } else { $this->view = 'Details'; } } break; case 'deleteVersion': if (!($this->userCanWrite($item->getId()) && $this->userCanWrite($item->getParentId()))) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_delete')); $this->_set_deleteView_errorPerms(); } else { if ($this->request->exist('confirm')) { $this->action = $view; $this->_set_redirectView(); } else { $this->view = 'Details'; } } break; case 'createFolder': case 'createDocument': case 'createItem': if ($this->request->exist('cancel')) { $this->_set_redirectView(); } else { $i = $this->request->get('item'); if (!$i || !isset($i['parent_id'])) { $this->feedback->log('error', 'Missing parameter.'); $this->view = 'DocmanError'; } else { $parent =& $item_factory->getItemFromDb($i['parent_id']); if (!$parent || $parent->getGroupId() != $this->getGroupId() || !$this->userCanWrite($parent->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_create')); $this->_set_createItemView_errorParentDoesNotExist($item, $get_show_view); } else { //Validations $new_item = $this->createItemFromUserInput(); $valid = $this->_validateRequest(array_merge($new_item->accept(new Docman_View_GetFieldsVisitor()), $new_item->accept(new Docman_View_GetSpecificFieldsVisitor(), array('request' => &$this->request)))); if ($user->isMember($this->getGroupId(), 'A') || $user->isMember($this->getGroupId(), 'N1') || $user->isMember($this->getGroupId(), 'N2')) { $news = $this->request->get('news'); if ($news) { $is_news_details = isset($news['details']) && trim($news['details']); $is_news_summary = isset($news['summary']) && trim($news['summary']); if ($is_news_details && !$is_news_summary) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_create_news_summary')); $valid = false; } if (!$is_news_details && $is_news_summary) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_create_news_details')); $valid = false; } } } if ($valid) { $this->action = $view; $this->_set_redirectView(); } else { // Propagate return page $this->_viewParams['token'] = $this->request->get('token'); $this->_viewParams['force_item'] = $new_item; $this->_viewParams['force_news'] = $this->request->get('news'); $this->_viewParams['force_permissions'] = $this->request->get('permissions'); $this->_viewParams['force_ordering'] = $this->request->get('ordering'); $this->_viewParams['display_permissions'] = $this->request->exist('user_has_displayed_permissions'); $this->_viewParams['display_news'] = $this->request->exist('user_has_displayed_news'); $this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); $this->_set_createItemView_afterCreate($view); } } } } break; case 'update': $this->_viewParams['recurseOnDocs'] = false; $this->_actionParams['recurseOnDocs'] = false; if ($this->request->get('recurse_on_doc') == 1) { $this->_viewParams['recurseOnDocs'] = true; $this->_actionParams['recurseOnDocs'] = true; } case 'update_wl': case 'new_version': if (!$this->userCanWrite($item->getId())) { $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_edit')); $this->view = 'Details'; } else { // For properties update ('update' action), we need to confirm // the recursive application of metadata update. if ($view == 'update' && $this->request->exist('recurse') && !$this->request->exist('cancel')) { $this->_viewParams['recurse'] = $this->request->get('recurse'); if (!$this->request->exist('validate_recurse')) { $updateConfirmed = false; } elseif ($this->request->get('validate_recurse') != 'true') { $updateConfirmed = false; } else { $updateConfirmed = true; } } else { $updateConfirmed = true; } $valid = true; if ($this->request->exist('confirm')) { //Validations if ($view == 'update') { $this->updateMetadataFromUserInput($item); $valid = $this->_validateRequest($item->accept(new Docman_View_GetFieldsVisitor())); } else { $this->updateItemFromUserInput($item); $valid = $this->_validateApprovalTable($this->request, $item) && $this->_validateRequest($item->accept(new Docman_View_GetSpecificFieldsVisitor(), array('request' => &$this->request))); } //Actions if ($valid && $updateConfirmed) { if ($view == 'update_wl') { $this->action = 'update'; } else { $this->action = $view; } } } //Views if ($valid && $updateConfirmed) { if ($redirect_to = Docman_Token::retrieveUrl($this->request->get('token'))) { $this->_viewParams['redirect_to'] = $redirect_to; } $this->view = 'RedirectAfterCrud'; } else { if ($view == 'update_wl') { $this->view = 'Update'; } else { if ($view == 'new_version') { // Keep fields values $v = $this->request->get('version'); $this->_viewParams['label'] = $v['label']; $this->_viewParams['changelog'] = $v['changelog']; if ($item instanceof Docman_EmbeddedFile) { $v = $item->getCurrentVersion(); $v->setContent($this->request->get('content')); } $this->view = 'NewVersion'; } else { $mdFactory = new Docman_MetadataFactory($this->_viewParams['group_id']); $mdFactory->appendAllListOfValuesToItem($item); if ($this->request->existAndNonEmpty('token')) { // propagate the token so the user will be // redirected to the original page even after // several properties update errors or // confirmations. $this->_viewParams['token'] = $this->request->get('token'); } $this->_viewParams['updateConfirmed'] = $updateConfirmed; // The item may have changed (new user input) unset($this->_viewParams['item']); $this->_viewParams['item'] =& $item; $this->view = 'Edit'; } } } } break; case 'change_view': $this->action = $view; break; case 'install': $this->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_alreadyinstalled')); $this->view = 'DocmanError'; break; case 'search': $this->view = 'Table'; break; case 'positionWithinFolder': $this->_viewParams['force_ordering'] = $this->request->get('default_position'); $this->_viewParams['exclude'] = $this->request->get('exclude'); $this->_viewParams['hierarchy'] =& $this->getItemHierarchy($root); $this->view = ucfirst($view); break; case 'permissionsForItem': $this->_viewParams['user_can_manage'] = $this->userCanManage($item->getId()); $this->view = ucfirst($view); break; case 'report_settings': $this->view = 'ReportSettings'; break; case 'report_del': if ($this->request->exist('report_id')) { $this->_actionParams['sReportId'] = (int) $this->request->get('report_id'); $this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; $this->action = $view; } $this->_viewParams['default_url_params'] = array('action' => 'report_settings'); $this->view = 'RedirectAfterCrud'; break; case 'report_upd': if ($this->request->exist('report_id')) { $this->_actionParams['sReportId'] = (int) $this->request->get('report_id'); $this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; $usScope = $this->request->get('scope'); if ($usScope === 'I' || $usScope === 'P') { $this->_actionParams['sScope'] = $usScope; } $this->_actionParams['description'] = $this->request->get('description'); $this->_actionParams['title'] = $this->request->get('title'); $this->_actionParams['sImage'] = (int) $this->request->get('image'); $this->action = $view; } $this->_viewParams['default_url_params'] = array('action' => 'report_settings'); $this->view = 'RedirectAfterCrud'; break; case 'report_import': if ($this->request->exist('import_search_report_from_group')) { $pm = ProjectManager::instance(); $srcGroup = $pm->getProjectFromAutocompleter($this->request->get('import_search_report_from_group')); if ($srcGroup && !$srcGroup->isError()) { $this->_actionParams['sGroupId'] = $this->_viewParams['group_id']; $this->_actionParams['sImportGroupId'] = $srcGroup->getGroupId(); $this->_actionParams['sImportReportId'] = null; if ($this->request->exist('import_report_id') && trim($this->request->get('import_report_id')) != '') { $this->_actionParams['sImportReportId'] = (int) $this->request->get('import_report_id'); } $this->action = $view; } } $this->_viewParams['default_url_params'] = array('action' => 'report_settings'); $this->view = 'RedirectAfterCrud'; break; case 'action_lock_add': $this->_actionParams['item'] = $item; $this->action = 'action_lock_add'; break; case 'action_lock_del': $this->_actionParams['item'] = $item; $this->action = 'action_lock_del'; break; case 'ajax_reference_tooltip': $this->view = 'AjaxReferenceTooltip'; break; default: $event_manager =& EventManager::instance(); $eParams = array('view' => $view, 'docmanPath' => $this->pluginPath, 'docmanThemePath' => $this->themePath); $event_manager->processEvent('plugin_docman_after_dispacher', $eParams); die(htmlspecialchars($view) . ' is not supported'); break; } }
/** * Add given user into the reviewer list if she's not already member. * * @access: private */ function _addUser($userId) { $dPm =& Docman_PermissionsManager::instance($this->item->getGroupId()); $um =& $this->_getUserManager(); $user =& $um->getUserById($userId); if ($dPm->userCanRead($user, $this->item->getId())) { if (!$this->isReviewer($user->getId())) { $dao =& $this->_getDao(); $added = $dao->addUser($this->table->getId(), $user->getId()); if ($added) { $this->reviewerCache[$user->getId()] = true; return true; } else { $this->err['db'][] = $user->getRealName(); } } else { $this->warn['double'][] = $user->getRealName(); } } else { $this->err['perm'][] = $user->getRealName(); } return false; }
function _getPermissionsManager() { return Docman_PermissionsManager::instance($this->_group_id); }
/** * Obtain instance of Docman_PermissionsManager * * @return Docman_PermissionsManager */ private function _getPermissionsManager() { return Docman_PermissionsManager::instance($this->getGroupId()); }
function getReportImage() { $html = ''; if ($this->report->getImage() !== null) { $itemId = $this->report->getImage(); if ($itemId > 0) { // Get Item $itemFactory = new Docman_ItemFactory($this->report->getGroupId()); $item = $itemFactory->getItemFromDb($itemId); if ($item !== null) { // Check perms $dPm =& Docman_PermissionsManager::instance($item->getGroupId()); $user =& $this->getCurrentUser(); $html .= "<div style=\"text-align:center\">\n"; if ($dPm->userCanRead($user, $item->getId())) { $html .= '<img src="' . $this->defaultUrl . '&id=' . $itemId . '" >'; } else { $html .= $GLOBALS['Language']->getText('plugin_docman', 'report_image_not_readable'); } $html .= "</div>\n"; } } } return $html; }
/** * Set the permission for a ugroup on an item. * * The difficult part of the algorithm comes from two point: * - There is a hierarchy between ugroups (@see ugroup_get_parent) * - There is a hierarchy between permissions (READ < WRITE < MANAGE) * * Let's see a scenario: * I've selected WRITE permission for Registered users and READ permission for Project Members * => Project Members ARE registered users therefore they have WRITE permission. * => WRITE is stronger than READ permission. * So the permissions wich will be set are: WRITE for registered and WRITE for project members * * The force parameter must be set to true if you want to bypass permissions checking (@see permission_add_ugroup). * Pretty difficult to know if a user can update the permissions which does not exist for a new item... * * @param $group_id integer The id of the project * @param $item_id integer The id of the item * @param $permission_definition array The definission of the permission (pretty name, relations between perms, internal name, ...) * @param $old_permissions array The permissions before * @param &$done_permissions array The permissions after * @param $ugroup_id The ugroup_id we want to set permission now * @param $wanted_permissions array The permissions the user has asked * @param &$history array Does a permission has been set ? * @param $force boolean true if you want to bypass permissions checking (@see permission_add_ugroup). * * @access protected */ function _setPermission($group_id, $item_id, $permission_definition, $old_permissions, &$done_permissions, $ugroup_id, $wanted_permissions, &$history, $force = false) { //Do nothing if we have already choose a permission for ugroup if (!isset($done_permissions[$ugroup_id])) { //if the ugroup has a parent if (($parent = ugroup_get_parent($ugroup_id)) !== false) { //first choose the permission for the parent $this->_setPermission($group_id, $item_id, $permission_definition, $old_permissions, $done_permissions, $parent, $wanted_permissions, $history, $force); //is there a conflict between given permissions? if ($parent = $this->_getBiggerOrEqualParent($permission_definition, $done_permissions, $parent, $wanted_permissions[$ugroup_id])) { //warn the user that there was a conflict $this->_controler->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docman', 'warning_perms', array($old_permissions[$ugroup_id]['ugroup']['name'], $old_permissions[$parent]['ugroup']['name'], $permission_definition[$done_permissions[$parent]]['label']))); //remove permissions which was set for the ugroup if (count($old_permissions[$ugroup_id]['permissions'])) { foreach ($old_permissions[$ugroup_id]['permissions'] as $permission => $nop) { permission_clear_ugroup_object($group_id, $permission, $ugroup_id, $item_id); $history[$permission] = true; } } //The permission is none (default) for this ugroup $done_permissions[$ugroup_id] = 100; } } //If the permissions have not been set (no parent || no conflict) if (!isset($done_permissions[$ugroup_id])) { //remove permissions if needed $perms_cleared = false; if (count($old_permissions[$ugroup_id]['permissions'])) { foreach ($old_permissions[$ugroup_id]['permissions'] as $permission => $nop) { if ($permission != $permission_definition[$wanted_permissions[$ugroup_id]]['type']) { //The permission has been changed permission_clear_ugroup_object($group_id, $permission, $ugroup_id, $item_id); $history[$permission] = true; $perms_cleared = true; $done_permissions[$ugroup_id] = 100; } else { //keep the old permission $done_permissions[$ugroup_id] = Docman_PermissionsManager::getDefinitionIndexForPermission($permission); } } } //If the user set an explicit permission and there was no perms before or they have been removed if ($wanted_permissions[$ugroup_id] != 100 && (!count($old_permissions[$ugroup_id]['permissions']) || $perms_cleared)) { //Then give the permission $permission = $permission_definition[$wanted_permissions[$ugroup_id]]['type']; permission_add_ugroup($group_id, $permission, $item_id, $ugroup_id, $force); $history[$permission] = true; $done_permissions[$ugroup_id] = $wanted_permissions[$ugroup_id]; } else { //else set none(default) permission $done_permissions[$ugroup_id] = 100; } } } }
/** * Manage deletion of a entire item hierarchy. * * It's the recommended and official way to delete a file in the docman * * @param Docman_Item $item Item to delete * @param User $user User who performs the delete * @param Boolean $cascadeWiki If there are wiki documents, do we delete corresponding in wiki page too ? * * @return Boolean success */ public function deleteSubTree(Docman_Item $item, User $user, $cascadeWiki) { if ($item && !$this->isRoot($item)) { // Cannot delete one folder if at least on of the document inside // cannot be deleted $dPm = Docman_PermissionsManager::instance($item->getGroupId()); $subItemsWritable = $dPm->currentUserCanWriteSubItems($item->getId()); if ($subItemsWritable) { $itemSubTree = $this->getItemSubTree($item, $user, false, true); if ($itemSubTree) { $deletor = new Docman_ActionsDeleteVisitor(); if ($itemSubTree->accept($deletor, array('user' => $user, 'cascadeWikiPageDeletion' => $cascadeWiki))) { return true; } } } else { throw new RuntimeException($GLOBALS['Language']->getText('plugin_docman', 'error_item_not_deleted_no_w')); } } return false; }
function _displayItem(&$item, $params) { $li_displayed = false; if ($this->stripFirstNode && !$this->firstNodeStripped) { $this->firstNodeStripped = true; if (isset($this->params['display_description']) && $this->params['display_description']) { $this->html .= '<p>' . $item->getDescription() . '</p>'; } } else { if ($item !== null && $this->_canDisplayItem($item)) { $this->html .= '<li id="item_' . $item->getId() . '" class="' . Docman_View_Browse::getItemClasses($params) . '">'; $params['expanded'] = true; $open = '_open'; if (!isset($this->params['item_to_move']) && user_get_preference(PLUGIN_DOCMAN_EXPAND_FOLDER_PREF . '_' . $item->getGroupId() . '_' . $item->getId()) === false) { $params['expanded'] = false; $open = ''; } $icon_src = $this->params['docman_icons']->getIconForItem($item, $params); $icon = '<img src="' . $icon_src . '" id="docman_item_icon_' . $item->getId() . '" class="docman_item_icon" />'; $this->html .= '<div>'; $action = isset($this->params['item_to_move']) ? false : $item->accept($this->get_action_on_icon, array('view' => &$this->view)); if ($action) { $class = $item->accept($this->get_class_for_link, array('view' => &$this->view)); if ($class) { $class .= $open; } $url = Docman_View_View::buildUrl($this->params['default_url'], array('action' => $action, 'id' => $item->getId())); $this->html .= '<a href="' . $url . '" id="docman_item_link_' . $item->getId() . '" class="' . $class . '">'; } $this->html .= $icon; //Display a lock icon for the locked document $dpm = Docman_PermissionsManager::instance($item->getGroupId()); if ($dpm->getLockFactory()->itemIsLocked($item)) { $lockIconSrc = $this->params['docman_icons']->getIcon('lock_delete.png'); $lockIcon = '<img src= "' . $lockIconSrc . '" id="docman_item_icon_locked_' . $item->getId() . '" class="docman_item_icon" />'; $this->html .= $lockIcon; } if ($action) { $this->html .= '</a>'; } $this->html .= '<span class="docman_item_title">'; if ($action) { $url = Docman_View_View::buildActionUrl($this->params, array('action' => 'show', 'id' => $item->getId()), false, isset($params['popup_doc']) ? true : false); $this->html .= '<a href="' . $url . '" id="docman_item_title_link_' . $item->getId() . '">'; } $this->html .= $this->hp->purify($item->getTitle(), CODENDI_PURIFIER_CONVERT_HTML); if ($action) { $this->html .= '</a>'; } $this->html .= '</span>'; $this->html .= $this->view->getItemMenu($item, $this->params); $this->js .= $this->view->getActionForItem($item); $this->html .= '</div>'; if (trim($item->getDescription()) != '') { $this->html .= '<div class="docman_item_description">' . $this->hp->purify($item->getDescription(), CODENDI_PURIFIER_BASIC, $item->getGroupId()) . '</div>'; } $li_displayed = true; } } return $li_displayed; }
/** * Create a report for table view based on URL */ function &get($reportId, $request, $item, &$feedback) { $report = null; $report = new Docman_Report(); // Drop all filters if ($request->exist('clear_filters')) { $this->initReport($report, $request, $item); $this->initColumns($report, $request); return $report; } $noDbReport = true; // First, try to find a report in DB //if($request->exist('report_id')) { // $reportId = (int) $request->get('report_id'); // todo Verify validity of the info //} if ($reportId > 0) { // todo Verify validity of the info $dao =& $this->getDao(); $dar = $dao->searchById($reportId); if ($dar && !$dar->isError() && $dar->rowCount() == 1) { $noDbReport = false; $row = $dar->getRow(); $report = new Docman_Report(); $report->initFromRow($row); $filterFactory = new Docman_FilterFactory($this->groupId); $fa = $filterFactory->addFiltersToReport($report); $this->initColumns($report, $request); } } if ($noDbReport) { // Init from url $this->initReport($report, $request, $item); $this->initFilters($report, $request, $feedback); $this->initColumns($report, $request); } // Save current report if ($request->exist('save_report')) { $um =& UserManager::instance(); $user = $um->getCurrentUser(); $dpm =& Docman_PermissionsManager::instance($this->groupId); $report->setUserId($user->getId()); // New report if ($request->get('save_report') == 'newp' || $request->get('save_report') == 'newi') { if ($request->exist('report_name')) { $reportName = $request->get('report_name'); // todo Validate report name $report->setScope('I'); if ($dpm->userCanAdmin($user)) { if ($request->get('save_report') == 'newp') { $report->setScope('P'); } } $report->setName($reportName); $this->saveReport($report); } } // Override an existing one if (is_numeric($request->get('save_report'))) { $reportId = (int) $request->get('save_report'); // validate reportId $updReportOk = false; $refReport = $this->getReportById($reportId); if ($refReport !== null) { if ($refReport->getGroupId() == $this->groupId) { if ($dpm->userCanAdmin($user)) { $updReportOk = true; } else { if ($refReport->getScope() == 'I' && $refReport->getUserId() == $user->getId()) { $updReportOk = true; } } } } if ($updReportOk) { if ($request->exist('report_name') && trim($request->get('report_name')) != '') { $refReport->setName($request->get('report_name')); } $refReport->setItemId($item->getId()); // Replace filters in ref report by the filters built from the URL. $refReport->setFiltersArray($report->getFiltersArray()); $this->saveReport($refReport); } } } return $report; }
/** * Return an item (we don't know the group_id) * @param int $item_id the id of the item to retrieve * @return Docman_Item */ protected function getItem($item_id) { $item = null; $dao = new Docman_ItemDao(CodendiDataAccess::instance()); if ($row = $dao->searchByid($item_id)->getRow()) { $item = Docman_ItemFactory::instance($row['group_id'])->getItemFromRow($row); $dPm = Docman_PermissionsManager::instance($row['group_id']); $user = UserManager::instance()->getCurrentUser(); if (!$dPm->userCanRead($user, $item->getId())) { $item = false; } } return $item; }
function _dispatch($view) { $user = $this->getUser(); $dpm = Docman_PermissionsManager::instance($this->getGroupId()); switch ($view) { case 'admin_watermark': $group_id = $this->request->get('group_id'); $dwmdf = new DocmanWatermark_MetadataFactory(); $md_id = $dwmdf->getMetadataIdFromGroupId($group_id); $this->_viewParams['md_id'] = $md_id; $this->_viewParams['group_id'] = $group_id; $md_arr = array(); $dmf = new Docman_MetadataFactory($group_id); $mdIter = $dmf->getMetadataForGroup(true); $mdIter->rewind(); while ($mdIter->valid()) { $md = $mdIter->current(); $md_arr[] = $md->getId(); $mdIter->next(); } if ($md_id != 0 && !in_array($md_id, $md_arr)) { $this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_metadata_deleted')); } $this->view = 'AdminWatermark'; break; case 'admin_set_watermark_metadata': $group_id = $this->request->get('group_id'); $id = $this->request->get('md_id'); $this->_actionParams['group_id'] = $group_id; $this->_actionParams['md_id'] = $id; $dwm = new DocmanWatermark_Metadata(); $dwm->setId($id); $dwm->setGroupId($group_id); $this->action = 'setup_metadata'; $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update_metadata')); $this->_viewParams['redirect_to'] = '?group_id=' . $group_id . '&action=admin_watermark'; $this->view = 'RedirectAfterCrud'; break; case 'admin_set_watermark_metadata_values': $mdf = new Docman_MetadataFactory($this->request->get('group_id')); $dwmf = new DocmanWatermark_MetadataFactory(); $md_id = $dwmf->getMetadataIdFromGroupId($this->request->get('group_id')); $mdLabel = $mdf->getLabelFromId($md_id); $mlvef = new Docman_MetadataListOfValuesElementFactory($md_id); $mlveIter = $mlvef->getIteratorByFieldId($md_id, $mdLabel, true); $mlveIter->rewind(); $arrValues = array(); $arrVals = array(); while ($mlveIter->valid()) { $dmv = $mlveIter->current(); $dwmv = new DocmanWatermark_MetadataValue(); if ($this->request->exist('chk_' . $dmv->getId())) { $watermark = 1; } else { $watermark = 0; } $dwmv->setValueId($dmv->getId()); $dwmv->setWatermark($watermark); $arrValues[] = $dwmv; $arrVals['value_id'][] = $dmv->getId(); $arrVals['watermark'][] = $watermark; $mlveIter->next(); } $iterValues = new ArrayIterator($arrValues); $this->_actionParams['group_id'] = $this->request->get('group_id'); $this->_actionParams['md_values'] = $iterValues; $this->action = 'setup_metadata_values'; $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update_metadata_values')); $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_watermark'; $this->view = 'RedirectAfterCrud'; break; case 'admin_import_from_project': $this->_actionParams['src_group_id'] = $this->request->get('project'); $this->_actionParams['target_group_id'] = $this->request->get('group_id'); $dwmif = new DocmanWatermark_MetadataImportFactory(); $dwmif->setSrcProjectId($this->request->get('project')); $dwmif->setTargetProjectId($this->request->get('group_id')); $dmf = new Docman_MetadataFactory($this->request->get('project')); $dwmf = new DocmanWatermark_MetadataFactory(); $md_id = $dwmf->getMetadataIdFromGroupId($dwmif->getSrcProjectId()); $mdIter = $dmf->findByName($dwmf->getMetadataNameFromId($md_id)); $mdIter->rewind(); $md = $mdIter->current(); $this->_actionParams['md'] = $md; $mdMap = $dwmif->getWatermarkMetadataMap($md); if ($mdMap['md'] != 0) { $this->action = 'import_from_project'; $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_imported_from_project')); $this->_viewParams['md_id'] = $md_id; $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_watermark'; } else { $this->feedback->log('info', $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_import_from_project_not_match')); $this->_viewParams['redirect_to'] = '?group_id=' . $this->request->get('group_id') . '&action=admin_import_metadata_check&import_group_id=' . $this->request->get('project'); } $this->view = 'RedirectAfterCrud'; break; case 'docmanwatermark_toggle_item': $this->action = 'docmanwatermark_toggle_item'; break; default: die(htmlspecialchars($view) . ' is not supported'); break; } }
function wiki_before_content() { $wiki_page = $this->request->get('wiki_page'); $group_id = $this->request->get('group_id'); $item_dao =& $this->_getItemDao(); $docman_references = HTML(); // Add js part for toogling referencers section. $js_code = ' function toggle_documents(id) { Element.toggle(id); toggle_image(id); } function toggle_image(id) { var img_element = $(\'img_\' + id); if (img_element.src.indexOf(\'' . util_get_image_theme("ic/toggle_plus.png") . '\') != -1) { img_element.src = \'' . util_get_image_theme("ic/toggle_minus.png") . '\'; img_element.title = \'' . $GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_hide_referencers') . '\'; } else { img_element.src = \'' . util_get_image_theme("ic/toggle_plus.png") . '\'; img_element.title = \'' . $GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_open_referencers') . '\'; } } '; $docman_references->pushContent(HTML::script(array('type' => 'text/javascript'), $js_code)); if ($item_dao->isWikiPageReferenced($wiki_page, $group_id)) { $docman_item_id = $item_dao->getItemIdByWikiPageAndGroupId($wiki_page, $group_id); if ($this->referrerIsDocument()) { $referrer_id = $this->getReferrerId($this->getReferrer()); } if (isset($docman_item_id) && $docman_item_id) { $content = HTML(); $script = HTML::script(array('type' => 'text/javascript'), "toggle_documents('documents');"); $user =& $this->getUser(); $dpm =& Docman_PermissionsManager::instance($group_id); // Wiki page could have many references in docman. if (is_array($docman_item_id)) { $icon = HTML::img(array('id' => 'img_documents', 'src' => util_get_image_theme("ic/toggle_minus.png"), 'title' => $GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_open_referencers'))); $linked_icon = HTML::a(array('href' => "#", 'onclick' => "javascript:toggle_documents('documents'); return false;"), $icon); // creating the title of the section regarding number of referencing documents and from where we arrived to this wiki page. if (count($docman_item_id) > 1) { $title = ""; if (isset($referrer_id) && $referrer_id) { $title = HTML::strong($GLOBALS['Language']->getText('plugin_docman', 'breadcrumbs_location') . " "); } else { $title = HTML::strong($GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_breadcrumbs_locations') . " "); } } else { if (count($docman_item_id) == 1) { $title = HTML::strong($GLOBALS['Language']->getText('plugin_docman', 'breadcrumbs_location') . " "); } else { $title = ""; } } //create Full legend of the section $legend = HTML::legend(array('class' => 'docman_md_frame'), count($docman_item_id) > 1 ? $linked_icon : "", $title, isset($referrer_id) && $referrer_id ? HTML($this->showReferrerPath($referrer_id, $group_id)) : ""); $details = HTML(); // create section body. if (isset($referrer_id) && $referrer_id) { if (count($docman_item_id) > 2) { $details->pushContent(HTML::H3($GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_other_locations') . " ")); } else { if (count($docman_item_id) == 2) { $details->pushContent(HTML::H3($GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_other_location') . " ")); } } } // create Referencing documents linked paths. foreach ($docman_item_id as $index => $value) { $details->pushContent($this->getDocumentPath($value, $group_id, isset($referrer_id) && $referrer_id ? $referrer_id : null)); } $content->pushContent(HTML::div(array('id' => 'documents'), $details)); if (count($docman_item_id) == 1) { $id = array_pop($docman_item_id); $docman_references->pushContent(HTML::strong($GLOBALS['Language']->getText('plugin_docman', 'breadcrumbs_location') . " ")); $docman_references->pushContent(HTML($this->getDocumentPath($id, $group_id))); $docman_references->pushContent(HTML::br()); } else { $docman_references->pushContent(HTML::br()); $docman_references->pushContent(HTML::fieldset(array('class' => 'docman_md_frame'), $legend, $content, $script)); } } else { if ($dpm->userCanAccess($user, $docman_item_id)) { $docman_references->pushContent(HTML::strong($GLOBALS['Language']->getText('plugin_docman', 'breadcrumbs_location') . " ")); $docman_references->pushContent(HTML($this->getDocumentPath($docman_item_id, $group_id))); //$docman_references->pushContent(HTML::br()); } } } } // Write documents paths on wiki view. // TODO: find another way to return a value. // Codendi_Request->params should not be public $this->request->params['html'] = $docman_references; }
public function fulltextsearch_event_does_docman_service_use_ugroup($params) { $manager = Docman_PermissionsManager::instance($params['project_id']); $ugroup_id = $params['ugroup_id']; $params['is_used'] = $manager->isUgroupUsed($ugroup_id); }
function &_getPermissionsManager() { $dpm =& Docman_PermissionsManager::instance($this->item->getGroupId()); return $dpm; }
/** * Returns an instance of PermissionsManager * * @param Project $project Used project * * @return Docman_PermissionsManager */ function getDocmanPermissionsManager($project) { return Docman_PermissionsManager::instance($project->getGroupId()); }
function _getlockInfo() { $html = ''; $dpm = Docman_PermissionsManager::instance($this->item->getGroupId()); if ($dpm->getLockFactory()->itemIsLocked($this->item)) { $lockInfos = $dpm->getLockFactory()->getLockInfoForItem($this->item); $locker = UserHelper::instance()->getLinkOnUserFromUserId($lockInfos['user_id']); $lockDate = format_date($GLOBALS['Language']->getText('system', 'datefmt'), $lockInfos['lock_date']); $html .= '<p>'; $html .= $GLOBALS['Language']->getText('plugin_docman', 'details_properties_lock_who', array($locker, $lockDate)); if (!$this->user_can_write) { $html .= $GLOBALS['Language']->getText('plugin_docman', 'details_properties_lock_info'); } $html .= '</p>'; } return $html; }