mydropdocumentspage.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 706 行 · 第 1/2 页
SVN-BASE
706 行
<?php/** * $Id: $ * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * */require_once("config/dmsDefaults.php");require_once(KT_DIR . "/ktapi/ktapi.inc.php");require_once(KT_LIB_DIR . "/plugins/plugin.inc.php");require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php");require_once(KT_LIB_DIR . "/dashboard/dashlet.inc.php");require_once(KT_DIR . "/plugins/ktcore/KTFolderActions.php");require_once(KT_DIR . "/ktapi/KTAPIFolder.inc.php");require_once(KT_LIB_DIR . "/roles/Role.inc");require_once(KT_LIB_DIR . "/roles/roleallocation.inc.php");require_once(KT_LIB_DIR . "/permissions/permissionutil.inc.php");require_once(KT_LIB_DIR . '/mime.inc.php');/* This page is run via an AJAX call from the update.js for this plugin. * It checks to see if both the dropdocuments folder and the users personal folder exist. * If they don't, it creates them and assigns permission and roles accordingly. * If the dropdocuments folder does exist it checks if the WorkSpaceOwner role exists. * If the role exists it assigns the current user to the role on the dropdocuments folder. * Therefore any users running the plugin after the dropdocuments folder has been created will have access to it too. * The underlying logic is that everyone is assigned to the WorkSpaceOwner Role, they have all permission except * Delete, Rename Folder, Manage security and Manage workflow on the dropdocuments folder. * This role is then assigned to their personal folder too (which is named according to their username) and is overidden * to give only the current user full rights to their folder. * Essentially everyone can look at the dropdocuments folder but will only see their own folder within it. */class MyDropDocumentsPage extends KTStandardDispatcher { function do_main() { $iRootID = (int)1; $oUser = $this->oUser; $sUserName = (string)$this->oUser->getUserName(); $this->ktapi = new KTAPI(); $this->session = $this->ktapi->start_system_session(); if(!Folder::FolderExistsName('DroppedDocuments', $iRootID)) { $root=$this->ktapi->get_root_folder(); //Create dropdocuments folder $userFolder = $root->add_folder('DroppedDocuments'); //In order to stop permission inheritance a copy of the parent permission object is created. //This copy is then used to set separate permissions for this folder. KTPermissionUtil::copyPermissionObject($userFolder->get_folder()); //If WorkSpaceOwner role doesn't exist, create it if(!$this->roleExistsName('WorkSpaceOwner')) { $oWorkSpaceOwnerRole = $this->createRole('WorkSpaceOwner'); if ($oWorkSpaceOwnerRole == null) { $this->session->logout(); return _kt('Error: Failed to create WorkSpaceOwner Role'); } } //$root=$this->ktapi->get_root_folder(); //$personalFolder = $root->get_folder_by_name('/dropdocuments/'.$sUserName); //Get the folder object $userFolderObject = $userFolder->get_folder(); //Get the permission object from the dropdocuments folder object $oUserPO = KTPermissionObject::get($userFolderObject->getPermissionObjectId()); //Check to see if there are duplicate WorkSpaceOwner roles. if (count($this->getRoleIdByName('WorkSpaceOwner')) > 1) { $this->session->logout(); return _kt('Error: cannot set user role permissions: more than one role named \'WorkSpaceOwner\' exists'); } //call the function to set the permission on the dropdocuments folder $this->setUserDocsPermissions($oUserPO); //Assign the current user to the WorkSpaceOwner role $this->setUserDocsRoleAllocation($userFolderObject); } else { $root = $this->ktapi->get_root_folder(); $userFolder = $root->get_folder_by_name('/DroppedDocuments'); //Get the dropdocuments folder object $userFolderObject = $userFolder->get_folder(); if(!$this->roleExistsName('WorkSpaceOwner')) { $oWorkSpaceOwnerRole = $this->createRole('WorkSpaceOwner'); if ($oWorkSpaceOwnerRole == null) { $this->session->logout(); return _kt('Error: Failed to create WorkSpaceOwner Role'); } //set permissions $oUserPO = KTPermissionObject::get($userFolderObject->getPermissionObjectId()); $this->setUserDocsPermissions($oUserPO); //assign current user to role $this->setUserDocsRoleAllocation($userFolderObject); } else { //update WrokSpaceOwner role to include current user $this->updateUserDocsRoleAllocation($userFolderObject); } } $iUserDocsFolderID = $this->getFolderID('DroppedDocuments'); $oUserDocsFolder = Folder::get($iUserDocsFolderID); if(!Folder::FolderExistsName($sUserName, $iUserDocsFolderID)) { $root=$this->ktapi->get_root_folder(); $userDocsFolder = $root->get_folder_by_name('/DroppedDocuments'); //create the personal folder. (Use the username to create it) $personalFolder = $userDocsFolder->add_folder($sUserName); //Copy the permission object to stop permission inheritance KTPermissionUtil::copyPermissionObject($personalFolder->get_folder()); //The role should exist by now. //In both the if and else statements for the dropdocuments above the role is created //If its doesn't exist by now there is an error if(!$this->roleExistsName('WorkSpaceOwner')) { $this->session->logout(); return _kt('Error: WorkSpaceOwner Role not setup, cannot assign to Personal Folder'); } $personalFolderRole = $root->get_folder_by_name('/DroppedDocuments/'.$sUserName); $PersonalFolderObject = ($personalFolderRole->get_folder()); //Get permission object $oPO = KTPermissionObject::get($PersonalFolderObject->getPermissionObjectId()); //Check for duplicate WorkSpaceOwner roles if (count($this->getRoleIdByName('WorkSpaceOwner')) > 1) { $this->session->logout(); return _kt('Error: cannot set personal folder role permissions: more than one role named \'WorkSpaceOwner\' exists'); } $this->setPersonalFolderPermissions($oPO); $this->updatePersonalFolderRoleAllocation($PersonalFolderObject); //folder just created so no top list of last modified documents $iMyDocsFolderID = $this->getFolderID($sUserName); $this->session->logout(); return _kt('<span class="descriptiveText"> You do not have any dropped documents </span><br><br><br>'); } else //if personal folder does exist { //Getting personal folder id $iMyDocsFolderID = $this->getFolderID($sUserName); if(!$this->roleExistsName('WorkSpaceOwner')) { $this->session->logout(); return _kt('Error: WorkSpaceOwner Role does not exist'); } else { $oTempPersonalFolder = $root->get_folder_by_name('/DroppedDocuments/'.$sUserName); $oPersonalFolder = $oTempPersonalFolder->get_folder(); //update WorkSpaceOwner role to include current user //Get permission object $oPO = KTPermissionObject::get($oPersonalFolder->getPermissionObjectId()); $this->setPersonalFolderPermissions($oPO); $this->updatePersonalFolderRoleAllocation($oPersonalFolder); } $fullPath = $oUserDocsFolder->getFullPath() . '/' . $sUserName; $aExternalWhereClauses[] = '(DT.transaction_namespace IN (?,?,?) AND (D.full_path LIKE "'.$fullPath.'/%"))'; $aExternalWhereParams[] = 'ktcore.transactions.create'; $aExternalWhereParams[] = 'ktcore.transactions.check_in'; $aExternalWhereParams[] = 'ktcore.transactions.event'; $aDocumentTransactions = $this->getTransactionsMatchingQuery($oUser, '', $aExternalWhereClauses, $aExternalWhereParams); if (empty($aDocumentTransactions)) { $this->session->logout(); return _kt('<span class="descriptiveText"> You do not have any dropped documents </span><br><br><br>'); } $maxcount = 5; $sReturnTable = '<span class="descriptiveText">'._kt('Recently Dropped Documents').'</span> <table width="100%" class="kt_collection drop_box" cellspacing="0"> <thead> <tr> <th width="100%">'._kt('Document').'</th> <th width="1%">'._kt('Date Dropped').'</th> </tr> </thead> <tbody>'; $sOddorEven = ''; $count = 1; $rendered = array(); foreach ($aDocumentTransactions as $aRow) { $documentId = $aRow['document_id']; if (in_array($documentId, $rendered)) { continue; } $rendered[] = $documentId; $oDocument = Document::get($documentId); $sContentType = KTMime::getIconPath($oDocument->getMimeTypeID()); $aAnchorData = $this->getDocInfo($documentId); $sLink = $aAnchorData[0]; $sShortDocName = $sDocName = $aAnchorData[1]; $iDocLength = strlen($sDocName); $iMax = 40; if ( $iDocLength > $iMax ) { $sShortDocName = substr($sDocName, 0, $iMax) . '...'; } $sOddorEven = ($count%2 == 0)?'even':'odd'; $sReturnTable .= '<tr class="'.$sOddorEven.'">'. '<td width="100%"><span class="contenttype '.$sContentType.'"><a title="'.$sDocName.'" href='.$sLink.'>'.$sShortDocName.'</a></span></td>'. '<td width="1%">'.$aRow['datetime'].'</td>'. '</tr>'; if (++$count > 5) { break; } } $location = 'browse.php?fFolderId='.$iMyDocsFolderID; $sReturnTable .= '</tbody>'. '</table>'. '<br>'. '<a href="'.$location.'">'._kt(' View All').' </a><br><br>'; $this->session->logout(); return $sReturnTable; } } function handleOutput($sOutput) { print $sOutput; } //This function is used to set the permission on the dropdocuments folder function setUserDocsPermissions($oUserPO) { //arrays returned from get Role ID's $aWorkSpaceOwnerRoleID = $this->getRoleIdByName('WorkSpaceOwner'); $aAdminGroupID = $this->getGroupIdByName('System Administrators'); //arrays used to make integers for $aAllowed array variable $iWorkSpaceOwnerRoleID = $aWorkSpaceOwnerRoleID[0]['id']; $iAdminGroupID = $aAdminGroupID[0]['id']; //$aBothAllowed is used to give permissions to the admin group and the WorkSpaceOwner role $aBothAllowed = array('group' => array($iAdminGroupID), 'role' => array($iWorkSpaceOwnerRoleID)); //$aAdminAllowed is used to give permissions to the admin group only $aAdminAllowed = array('group' => array($iAdminGroupID)); //Get the list of permissions $aPermissions = KTPermission::getList(); foreach ($aPermissions as $oPermission) { //If the permission is not one of the below then both are allowed the permission //Otherwise only the admin group is allowed the permission if($oPermission->getHumanName() != 'Delete' && $oPermission->getHumanName() != 'Rename Folder' && $oPermission->getHumanName() != 'Manage security' && $oPermission->getHumanName() != 'Manage workflow') { KTPermissionUtil::setPermissionForId($oPermission, $oUserPO, $aBothAllowed); } else { KTPermissionUtil::setPermissionForId($oPermission, $oUserPO, $aAdminAllowed); } } //UPdate the permission lookup KTPermissionUtil::updatePermissionLookupForPO($oUserPO);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?