/**
  * Method to create the DroppedDocuments folder within the Root Folder
  *
  * @return string|null Returns an error message or null on success
  */
 function createDropDocsFolder()
 {
     $root = $this->ktapi->get_root_folder();
     if (PEAR::isError($root)) {
         $default->log->debug('MyDropDocuments: could not get root folder ' . $root->getMessage());
         return _kt('Error - could not get the root folder: ') . $root->getMessage();
     }
     //Create dropdocuments folder
     $dropDocsFolder = $root->add_folder('DroppedDocuments');
     if (PEAR::isError($dropDocsFolder)) {
         $default->log->debug('MyDropDocuments: could not create DroppedDocuments folder ' . $dropDocsFolder->getMessage());
         return _kt('Error - could not create the DropppedDocuments folder: ') . $dropDocsFolder->getMessage();
     }
     // Get the DropDocuments folder object
     $dropDocsFolderObject = $dropDocsFolder->get_folder();
     // The folder must define its own permissions so create a copy of the root folder
     KTPermissionUtil::copyPermissionObject($dropDocsFolderObject);
     // Each user is added to the WorkSpaceOwner role on their personal folder
     // Check if the role exists and create it if it doesn't
     if (!$this->roleExistsName('WorkSpaceOwner')) {
         $oWorkSpaceOwnerRole = $this->createRole('WorkSpaceOwner');
         if ($oWorkSpaceOwnerRole == null) {
             return _kt('Error: Failed to create WorkSpaceOwner Role');
         }
     }
     // Get the permission object from the dropdocuments folder object
     $oDropDocsPO = KTPermissionObject::get($dropDocsFolderObject->getPermissionObjectId());
     if (PEAR::isError($oDropDocsPO)) {
         $default->log->debug('MyDropDocuments: could not get permission object for DroppedDocuments folder ' . $oDropDocsPO->getMessage());
         return _kt('Error - could not create the DropppedDocuments folder: ') . $oDropDocsPO->getMessage();
     }
     // Check to see if there are duplicate WorkSpaceOwner roles.
     if (count($this->getRoleIdByName('WorkSpaceOwner')) > 1) {
         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($oDropDocsPO);
     // Assign the current user to the WorkSpaceOwner role
     $this->setUserDocsRoleAllocation($dropDocsFolderObject);
     return null;
 }
Пример #2
0
 function do_createUnit()
 {
     $aOptions = array('redirect_to' => array('main'), 'message' => _kt('Invalid folder chosen'));
     $oParentFolder = $this->oValidator->validateFolder($_REQUEST['browse'], $aOptions);
     $aOptions = array('redirect_to' => array('addUnit', sprintf('browse=%d', $oParentFolder->getId())), 'message' => _kt('No name given'));
     $sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions);
     $aOptions['message'] = _kt('A unit with that name already exists.');
     $sName = $this->oValidator->validateDuplicateName('Unit', $sName, $aOptions);
     $oFolder = KTFolderUtil::add($oParentFolder, $sName, $this->oUser);
     $aOptions = array('redirect_to' => array('addUnit2', sprintf('fFolderId=%d&unit_name=%s', $oParentFolder->getId(), $sName)), 'defaultmessage' => 'Error creating folder');
     $this->oValidator->notError($oFolder, $aOptions);
     KTPermissionUtil::copyPermissionObject($oFolder);
     $oUnit = Unit::createFromArray(array('name' => $sName, 'folderid' => $oFolder->getId()));
     return $this->successRedirectToMain(_kt('Unit created'));
 }
Пример #3
0
 function copy($oSrcFolder, $oDestFolder, $oUser, $sReason, $sDestFolderName = NULL, $copyAll = true)
 {
     $sDestFolderName = empty($sDestFolderName) ? $oSrcFolder->getName() : $sDestFolderName;
     if (KTFolderUtil::exists($oDestFolder, $sDestFolderName)) {
         return PEAR::raiseError(_kt("Folder with the same name already exists in the new parent folder"));
     }
     //
     // FIXME the failure cleanup code here needs some serious work.
     //
     $oPerm = KTPermission::getByName('ktcore.permissions.read');
     $oBaseFolderPerm = KTPermission::getByName('ktcore.permissions.addFolder');
     if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oBaseFolderPerm, $oDestFolder)) {
         return PEAR::raiseError(_kt('You are not allowed to create folders in the destination.'));
     }
     // Check if the source folder inherits its permissions
     // Get source PO id and its parent PO id
     $iSrcPoId = $oSrcFolder->getPermissionObjectID();
     $oSrcParent = Folder::get($oSrcFolder->getParentID());
     $iSrcParentPoId = $oSrcParent->getPermissionObjectID();
     // If the folder defines its own permissions then we copy the permission object
     // If the source folder inherits permissions we must change it to inherit from the new parent folder
     $bInheritPermissions = false;
     if ($iSrcPoId == $iSrcParentPoId) {
         $bInheritPermissions = true;
     }
     $aFolderIds = array();
     // of oFolder
     $aDocuments = array();
     // of oDocument
     $aFailedDocuments = array();
     // of String
     $aFailedFolders = array();
     // of String
     $aRemainingFolders = array($oSrcFolder->getId());
     DBUtil::startTransaction();
     while (!empty($aRemainingFolders) && $copyAll) {
         $iFolderId = array_pop($aRemainingFolders);
         $oFolder = Folder::get($iFolderId);
         if (PEAR::isError($oFolder) || $oFolder == false) {
             DBUtil::rollback();
             return PEAR::raiseError(sprintf(_kt('Failure resolving child folder with id = %d.'), $iFolderId));
         }
         // don't just stop ... plough on.
         if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oFolder)) {
             $aFolderIds[] = $iFolderId;
         } else {
             $aFailedFolders[] = $oFolder->getName();
         }
         // child documents
         $aChildDocs = Document::getList(array('folder_id = ?', array($iFolderId)));
         foreach ($aChildDocs as $oDoc) {
             if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDoc)) {
                 $aDocuments[] = $oDoc;
             } else {
                 $aFailedDocuments[] = $oDoc->getName();
             }
         }
         // child folders.
         $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
         $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
     }
     if (!empty($aFailedDocuments) || !empty($aFailedFolders)) {
         $sFD = '';
         $sFF = '';
         if (!empty($aFailedDocuments)) {
             $sFD = _kt('Documents: ') . implode(', ', $aFailedDocuments) . '. ';
         }
         if (!empty($aFailedFolders)) {
             $sFF = _kt('Folders: ') . implode(', ', $aFailedFolders) . '.';
         }
         return PEAR::raiseError(_kt('You do not have permission to copy these items. ') . $sFD . $sFF);
     }
     // first we walk the tree, creating in the new location as we go.
     // essentially this is an "ok" pass.
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $aFolderMap = array();
     $sTable = 'folders';
     $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? ';
     $aParams = array($oSrcFolder->getId());
     $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
     unset($aRow['id']);
     $aRow['name'] = $sDestFolderName;
     $aRow['description'] = $sDestFolderName;
     $aRow['parent_id'] = $oDestFolder->getId();
     $aRow['parent_folder_ids'] = sprintf('%s,%s', $oDestFolder->getParentFolderIDs(), $oDestFolder->getId());
     $aRow['full_path'] = $oDestFolder->getFullPath() . '/' . $aRow['name'];
     $id = DBUtil::autoInsert($sTable, $aRow);
     if (PEAR::isError($id)) {
         DBUtil::rollback();
         return $id;
     }
     $sSrcFolderId = $oSrcFolder->getId();
     $aFolderMap[$sSrcFolderId]['parent_id'] = $id;
     $aFolderMap[$sSrcFolderId]['parent_folder_ids'] = $aRow['parent_folder_ids'];
     $aFolderMap[$sSrcFolderId]['full_path'] = $aRow['full_path'];
     $aFolderMap[$sSrcFolderId]['name'] = $aRow['name'];
     $oNewBaseFolder = Folder::get($id);
     $res = $oStorage->createFolder($oNewBaseFolder);
     if (PEAR::isError($res)) {
         // it doesn't exist, so rollback and raise..
         DBUtil::rollback();
         return $res;
     }
     $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true));
     while (!empty($aRemainingFolders) && $copyAll) {
         $iFolderId = array_pop($aRemainingFolders);
         $aParams = array($iFolderId);
         $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams));
         unset($aRow['id']);
         // since we are nested, we will have solved the parent first.
         $sPrevParentId = $aRow['parent_id'];
         $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']]['parent_id'];
         $aRow['parent_folder_ids'] = sprintf('%s,%s', $aFolderMap[$sPrevParentId]['parent_folder_ids'], $aRow['parent_id']);
         $aRow['full_path'] = sprintf('%s/%s', $aFolderMap[$sPrevParentId]['full_path'], $aRow['name']);
         $id = DBUtil::autoInsert($sTable, $aRow);
         if (PEAR::isError($id)) {
             $oStorage->removeFolder($oNewBaseFolder);
             DBUtil::rollback();
             return $id;
         }
         $aFolderMap[$iFolderId]['parent_id'] = $id;
         $aFolderMap[$iFolderId]['parent_folder_ids'] = $aRow['parent_folder_ids'];
         $aFolderMap[$iFolderId]['full_path'] = $aRow['full_path'];
         $aFolderMap[$iFolderId]['name'] = $aRow['name'];
         $oNewFolder = Folder::get($id);
         $res = $oStorage->createFolder($oNewFolder);
         if (PEAR::isError($res)) {
             // first delete, then rollback, then fail out.
             $oStorage->removeFolder($oNewBaseFolder);
             DBUtil::rollback();
             return $res;
         }
         $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true));
         $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds);
     }
     // now we can go ahead.
     foreach ($aDocuments as $oDocument) {
         $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']);
         $res = KTDocumentUtil::copy($oDocument, $oChildDestinationFolder);
         if (PEAR::isError($res) || $res === false) {
             $oStorage->removeFolder($oNewBaseFolder);
             DBUtil::rollback();
             return PEAR::raiseError(_kt('Delete Aborted. Unexpected failure to copydocument: ') . $oDocument->getName() . $res->getMessage());
         }
     }
     $sComment = sprintf(_kt("Folder copied from %s to %s"), $oSrcFolder->getFullPath(), $oDestFolder->getFullPath());
     if ($sReason !== null) {
         $sComment .= sprintf(_kt(" (reason: %s)"), $sReason);
     }
     $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $oFolder->getId(), 'comment' => $sComment, 'transactionNS' => 'ktcore.transactions.copy', 'userid' => $oUser->getId(), 'ip' => Session::getClientIP()));
     // If the folder inherits its permissions then we set it to inherit from the new parent folder and update permissions
     // If it defines its own then copy the permission object over
     if ($bInheritPermissions) {
         $aOptions = array('evenifnotowner' => true);
         KTPermissionUtil::inheritPermissionObject($oNewBaseFolder, $aOptions);
     } else {
         KTPermissionUtil::copyPermissionObject($oNewBaseFolder);
     }
     // and store
     DBUtil::commit();
     return true;
 }
Пример #4
0
 /**
  * Creates a copy of the current permissions.
  *
  * @author KnowledgeTree Team
  * @access public
  */
 public function overrideAllocation()
 {
     $object = $this->_logTransaction(_kt('Override permissions from parent'), 'ktcore.transactions.permissions_change');
     KTPermissionUtil::copyPermissionObject($object);
 }
Пример #5
0
 function _copyPermissions()
 {
     $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => _kt('Override permissions from parent'), 'transactionNS' => 'ktcore.transactions.permissions_change', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP()));
     $aOptions = array('defaultmessage' => _kt('Error updating permissions'), 'redirect_to' => array('edit', sprintf('fFolderId=%d', $this->oFolder->getId())));
     $this->oValidator->notErrorFalse($oTransaction, $aOptions);
     KTPermissionUtil::copyPermissionObject($this->oFolder);
 }
Пример #6
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/foldermanagement/Folder.inc';
require_once KT_LIB_DIR . '/permissions/permissionutil.inc.php';
error_reporting(E_ALL);
$oFolder = Folder::get(19);
var_dump($oFolder->getPermissionObjectID());
KTPermissionUtil::copyPermissionObject($oFolder);
var_dump($oFolder->getPermissionObjectID());