function getMetaDataForm($groupId, $mdId) { $mdf = new Docman_MetadataFactory($groupId); $mdIter = $mdf->getMetadataForGroup(true); $html = '<h3>' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_confidentiality_field') . '</h3>'; $html .= '<p>' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_select_field'); $html .= '<form name="metadata_field" method="post" action="?group_id=' . $groupId . '&action=admin_set_watermark_metadata">'; $html .= '<select name="md_id" onchange="javascript:document.metadata_field.submit()">'; $html .= '<option value="none">' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_none') . '</option>'; $mdIter->rewind(); $md_arr = array(); while ($mdIter->valid()) { $md = $mdIter->current(); if ($md->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) { $id = $md->getId(); $md_arr[] = $id; if ($md->getLabel() != 'status' && $id != 100) { $html .= '<option '; if ($mdId == $id) { $html .= 'selected '; } $html .= 'value="' . $id . '">' . $md->getName() . '</option>'; } } $mdIter->next(); } $html .= '</select>'; $html .= '<input name="submit_metadatafield" type="submit" value="' . $GLOBALS['Language']->getText('plugin_docmanwatermark', 'admin_update') . '">'; $html .= '</form></p>'; return $html; }
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 _dispatch($view, $item, $root, $get_show_view) { $item_factory =& $this->_getItemFactory(); $user =& $this->getUser(); $dpm = $this->_getPermissionsManager(); 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 { $dPm = $this->_getPermissionsManager(); if ($dPm->getLockFactory()->itemIsLocked($item)) { $this->feedback->log('warning', $GLOBALS['Language']->getText('plugin_docman', 'event_lock_add')); } $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_ApprovalTableFactoriesFactory::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; } }
/** * */ function getFiltersOptions($params, $displayedFilters) { $html = ''; $html .= '<div id="docman_report_options">'; $html .= '<strong>' . $GLOBALS['Language']->getText('plugin_docman', 'report_filters_options') . '</strong> '; // // Add a new filter // $html .= $GLOBALS['Language']->getText('plugin_docman', 'report_add_filter'); $html .= ' '; $html .= '<select name="add_filter" id="plugin_docman_report_add_filter">'; $html .= $this->getSelectOption('--', '--'); // Std metadata $mdFactory = new Docman_MetadataFactory($this->report->getGroupId()); $mdIter = $mdFactory->getMetadataForGroup(true); $mdIter->rewind(); while ($mdIter->valid()) { $md =& $mdIter->current(); if (!in_array($md->getLabel(), $displayedFilters)) { $html .= $this->getSelectOption($md->getLabel(), $md->getName(), ''); } $mdIter->next(); } // Special filters $gsmd = $this->report->getGlobalSearchMetadata(); $itmd = $this->report->getItemTypeSearchMetadata(); $showGlobalSearch = !in_array($gsmd->getLabel(), $displayedFilters); $showItemTypeSearch = !in_array($itmd->getLabel(), $displayedFilters); if ($showGlobalSearch || $showItemTypeSearch) { $html .= $this->getSelectOption('--', '--'); if ($showGlobalSearch) { $html .= $this->getSelectOption($gsmd->getLabel(), $gsmd->getName(), ''); } if ($showItemTypeSearch) { $html .= $this->getSelectOption($itmd->getLabel(), $itmd->getName(), ''); } } $html .= '</select>'; // // Advanced search // if ($this->report->advancedSearch) { $html .= '<input type="hidden" name="advsearch" value="1" />'; $advSearchToggle = 0; } else { $advSearchToggle = 1; } $advSearchUrl = $this->view->_buildSearchUrl($params, array('advsearch' => $advSearchToggle)); $html .= ' '; $html .= $GLOBALS['Language']->getText('plugin_docman', 'filters_advsearch_' . $advSearchToggle, array($advSearchUrl)); $html .= '</div><!-- docman_report_options-->'; return $html; }
function initFilters(&$report, $request, &$feedback) { $filterFactory = new Docman_FilterFactory($this->groupId); $mdFactory = new Docman_MetadataFactory($this->groupId); $mdIter = $mdFactory->getMetadataForGroup(true); $mdIter->rewind(); while ($mdIter->valid()) { $md = $mdIter->current(); $filter = $filterFactory->createFilterOnMatch($md, $request, $report->getAdvancedSearch()); $this->_validateFilterAndCreate($report, $filter, $feedback); $mdIter->next(); } // Special case for a fake metadata: generic text search $filter = $filterFactory->getGlobalSearchFilter($request); $this->_validateFilterAndCreate($report, $filter, $feedback); $filter = $filterFactory->getItemTypeSearchFilter($request, $report->getAdvancedSearch()); $this->_validateFilterAndCreate($report, $filter, $feedback); }
function getMetadataCompareTable(&$sthToImport) { $html = ''; // True if there is sth to import in dst project. $sthToImport = false; // For source project, only get the 'Used' metadata. $srcMdFactory = new Docman_MetadataFactory($this->srcGo->getGroupId()); $srcMdIter = $srcMdFactory->getMetadataForGroup(true); // For destination (current) project, get all metadata. $dstMdFactory = new Docman_MetadataFactory($this->dstGo->getGroupId()); $dstMdIter = $dstMdFactory->getMetadataForGroup(); $dstMdArray = $this->getArrayFromIterator($dstMdIter, 'getLabel'); // Get mapping between the 2 definitions $mdMap = array(); $srcMdFactory->getMetadataMapping($this->dstGo->getGroupId(), $mdMap); $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_desc', array($this->dstGo->getPublicName(), $this->srcGo->getPublicName())); // Table $html .= "<table border=\"1\">\n"; $html .= "<tr>\n"; $html .= "<th colspan=\"2\">" . $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_prop') . "</th>\n"; $html .= "<th>" . $this->srcGo->getPublicName() . "</th>\n"; $html .= "<th>" . $this->dstGo->getPublicName() . "</th>\n"; $html .= "<th>" . $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_diff', array($this->dstGo->getPublicName(), $this->srcGo->getPublicName())) . "</th>\n"; $html .= "<th>" . $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_action', array($this->dstGo->getPublicName())) . "</th>\n"; $html .= "</tr>\n"; // Keep a trace of metadata that matched in the dst metadata list. $matchingMd = array(); $srcMdIter->rewind(); while ($srcMdIter->valid()) { $srcMd = $srcMdIter->current(); $dstMd = null; // // Compute the differences between the 2 projects // $dstMdStatus = 'missing'; $dstMdLabel = ''; if ($srcMdFactory->isRealMetadata($srcMd->getLabel())) { if (isset($mdMap['md'][$srcMd->getId()])) { $dstMdLabel = $srcMdFactory->getLabelFromId($mdMap['md'][$srcMd->getId()]); } } else { $dstMdLabel = $srcMd->getLabel(); } if (isset($dstMdArray[$dstMdLabel])) { $dstMd = $dstMdArray[$dstMdLabel]; if ($dstMd !== false) { $matchingMd[$dstMdLabel] = true; $dstMdStatus = 'equivalent'; if ($dstMd->equals($srcMd)) { $dstMdStatus = 'equals'; } else { $sthToImport = true; } } else { $sthToImport = true; } } else { // The metadata is not in the metadata map list, check if it's // not a name conflict $dstMdi = $dstMdFactory->findByName($srcMd->getName()); if ($dstMdi->count() == 1) { $dstMdStatus = 'conflict'; } else { $sthToImport = true; } } // // Display result // $html .= "<tr>\n"; // Property $html .= "<td colspan=\"2\" style=\"font-weight: bold;\">"; $html .= $srcMd->getName(); $html .= "</td>"; // Presence in source project $html .= "<td align=\"center\">"; $html .= '<img src="' . $this->docmanIcons->getThemeIcon('tick.png') . '" />'; $html .= "</td>"; // Presence in destination project $html .= "<td align=\"center\">"; switch ($dstMdStatus) { case 'equals': case 'equivalent': $html .= '<img src="' . $this->docmanIcons->getThemeIcon('tick.png') . '" />'; break; } $html .= "</td>"; // Differences $html .= "<td class=\"docman_md_" . $dstMdStatus . "\">"; switch ($dstMdStatus) { case 'equivalent': case 'missing': case 'conflict': $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_status_' . $dstMdStatus); break; } $html .= "</td>"; // Action $html .= "<td>"; switch ($dstMdStatus) { case 'equals': // Nothing to do break; case 'equivalent': $diffArray = $this->checkMdDifferences($srcMd, $dstMd, $mdMap['love']); $diffStr = '<ul style="padding:0;padding-left:1.5em;margin:0;"><li>'; $diffStr .= implode('</li><li>', $diffArray); $diffStr .= '</li></ul>'; $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_update_md', array($srcMd->getName(), $this->dstGo->getPublicName(), $diffStr)); break; case 'missing': $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_import_md', array($srcMd->getName())); break; case 'conflict': $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_conflict'); break; } $html .= "</td>"; $html .= "</tr>\n"; // // List of values // if ($srcMd->getType() == PLUGIN_DOCMAN_METADATA_TYPE_LIST) { if ($dstMd !== null) { $html .= $this->getLoveCompareTable($srcMd, $dstMd, $mdMap, $sthToImport); } } unset($dstMd); $srcMdIter->next(); } // Append to the table the metadata in the dst project that where not // present in the src project. foreach ($dstMdArray as $md) { if (!isset($matchingMd[$md->getLabel()])) { $html .= "<tr>\n"; // Name $html .= "<td colspan=\"2\" style=\"font-weight: bold;\">"; $html .= $md->getName(); $html .= "</td>"; // Presence in source project $html .= "<td></td>"; // Presence in destination project $html .= "<td align=\"center\">"; $html .= '<img src="' . $this->docmanIcons->getThemeIcon('tick.png') . '" />'; $html .= "</td>"; // Differences $html .= "<td></td>"; // Action $html .= "<td></td>"; $html .= "</td>"; $html .= "</tr>\n"; } } $html .= "</table>\n"; return $html; }