示例#1
0
 function add($oParentFolder, $sFolderName, $oUser)
 {
     $folderid = $oParentFolder->getId();
     // check for conflicts first
     if (Folder::folderExistsName($sFolderName, $folderid)) {
         return PEAR::raiseError(sprintf(_kt('The folder %s already exists.'), $sFolderName));
     }
     $oFolder = KTFolderUtil::_add($oParentFolder, $sFolderName, $oUser);
     if (PEAR::isError($oFolder)) {
         return $oFolder;
     }
     $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $oFolder->getId(), 'comment' => _kt('Folder created'), 'transactionNS' => 'ktcore.transactions.create', 'userid' => $oUser->getId(), 'ip' => Session::getClientIP()));
     // fire subscription alerts for the new folder
     $oSubscriptionEvent = new SubscriptionEvent();
     $oSubscriptionEvent->AddFolder($oFolder, $oParentFolder);
     return $oFolder;
 }
示例#2
0
 function import()
 {
     $res = $this->oStorage->init();
     if (PEAR::isError($res)) {
         $this->oStorage->cleanup();
         return $res;
     }
     $res = $this->_importfolder($this->oFolder, "/");
     if (PEAR::isError($res)) {
         $this->oStorage->cleanup();
         return $res;
     }
     if (count($this->uploadedDocs) > 0) {
         // Bulk action subscription notification
         $oSubscriptionEvent = new SubscriptionEvent();
         $oSubscriptionEvent->notifyBulkDocumentAction($this->uploadedDocs, 'AddDocument', $this->oFolder);
     } elseif (count($this->uploadedFolders) > 0) {
         $oSubscriptionEvent = new SubscriptionEvent();
         $oSubscriptionEvent->notifyBulkDocumentAction($this->uploadedFolders, 'AddFolder', $this->oFolder);
     }
     $this->oStorage->cleanup();
     return;
 }
 function do_main()
 {
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $aOptions = array();
     $iVersion = KTUtil::arrayGet($_REQUEST, 'version');
     session_write_close();
     if ($iVersion) {
         $oVersion = KTDocumentContentVersion::get($iVersion);
         $aOptions['version'] = sprintf('%d.%d', $oVersion->getMajorVersionNumber(), $oVersion->getMinorVersionNumber());
         $res = $oStorage->downloadVersion($this->oDocument, $iVersion);
     } else {
         $res = $oStorage->download($this->oDocument);
     }
     if ($res === false) {
         $this->addErrorMessage(_kt('The file you requested is not available - please contact the system administrator if this is incorrect.'));
         redirect(generateControllerLink('viewDocument', sprintf(_kt('fDocumentId=%d'), $this->oDocument->getId())));
         exit(0);
     }
     $oDocumentTransaction =& new DocumentTransaction($this->oDocument, _kt('Document downloaded'), 'ktcore.transactions.download', $aOptions);
     $oDocumentTransaction->create();
     // fire subscription alerts for the downloaded document
     $oKTConfig =& KTConfig::getSingleton();
     $bNotifications = $oKTConfig->get('export/enablenotifications', 'on') == 'on' ? true : false;
     if ($bNotifications) {
         $oSubscriptionEvent = new SubscriptionEvent();
         $oFolder = Folder::get($this->oDocument->getFolderID());
         $oSubscriptionEvent->DownloadDocument($this->oDocument, $oFolder);
     }
     exit(0);
 }
 function do_removeSubscriptions()
 {
     $foldersubscriptions = KTUtil::arrayGet($_REQUEST, 'foldersubscriptions');
     $documentsubscriptions = KTUtil::arrayGet($_REQUEST, 'documentsubscriptions');
     if (empty($foldersubscriptions) && empty($documentsubscriptions)) {
         $this->errorRedirectToMain(_kt('No subscriptions were chosen'));
     }
     $iSuccesses = 0;
     $iFailures = 0;
     if (!empty($foldersubscriptions)) {
         foreach ($foldersubscriptions as $iSubscriptionId) {
             $oSubscription = Subscription::get($iSubscriptionId, SubscriptionEvent::subTypes('Folder'));
             if ($oSubscription) {
                 $oSubscription->delete();
                 $iSuccesses++;
             } else {
                 $iFailures++;
             }
         }
     }
     if (!empty($documentsubscriptions)) {
         foreach ($documentsubscriptions as $iSubscriptionId) {
             $oSubscription = Subscription::get($iSubscriptionId, SubscriptionEvent::subTypes('Document'));
             if ($oSubscription) {
                 $oSubscription->delete();
                 $iSuccesses++;
             } else {
                 $iFailures++;
             }
         }
     }
     $sMessage = _kt("Subscriptions removed") . ": ";
     if ($iFailures) {
         $sMessage .= sprintf(_kt('%d successful, %d failures'), $iSuccesses, $iFailures);
     } else {
         $sMessage .= sprintf('%d', $iSuccesses);
     }
     $this->successRedirectToMain($sMessage);
     exit(0);
 }
 /**
  * Add a folder to the archive
  *
  * @param unknown_type $zip
  * @param unknown_type $folderId
  * @return unknown
  */
 public function addFolder(&$zip, $folderId)
 {
     $oFolder = Folder::get($folderId);
     if (PEAR::isError($oFolder)) {
         $this->errors[] = _kt('Folder cannot be exported, an error occurred: ') . $oFolder->getMessage();
         return $oFolder;
     }
     $sFolderDocs = $oFolder->getDocumentIDs($folderId);
     if (PEAR::isError($sFolderDocs)) {
         $default->log->error('Download Queue: get document ids for folder caused an error: ' . $sFolderDocs->getMessage());
         $sFolderDocs = '';
     }
     // Add folder to zip
     $zip->addFolderToZip($oFolder);
     $aDocuments = array();
     if (!empty($sFolderDocs)) {
         $aDocuments = explode(',', $sFolderDocs);
     }
     // Get all the folders within the current folder
     $sWhereClause = "parent_folder_ids like '%,{$folderId}'\n            OR parent_folder_ids like '%,{$folderId},%'\n            OR parent_folder_ids like '{$folderId},%'\n            OR parent_id = {$folderId}";
     $aFolderList = $oFolder->getList($sWhereClause);
     $aLinkingFolders = $this->getLinkingEntities($aFolderList);
     $aFolderList = array_merge($aFolderList, $aLinkingFolders);
     $aFolderObjects = array();
     $aFolderObjects[$folderId] = $oFolder;
     // Export the folder structure to ensure the export of empty directories
     if (!empty($aFolderList)) {
         foreach ($aFolderList as $k => $oFolderItem) {
             if ($oFolderItem->isSymbolicLink()) {
                 $oFolderItem = $oFolderItem->getLinkedFolder();
             }
             if (Permission::userHasFolderReadPermission($oFolderItem)) {
                 // Get documents for each folder
                 $sFolderItemId = $oFolderItem->getID();
                 $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);
                 if (!empty($sFolderItemDocs)) {
                     $aFolderDocs = explode(',', $sFolderItemDocs);
                     $aDocuments = array_merge($aDocuments, $aFolderDocs);
                 }
                 $zip->addFolderToZip($oFolderItem);
                 $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
             }
         }
     }
     // Add all documents to the export
     if (!empty($aDocuments)) {
         foreach ($aDocuments as $sDocumentId) {
             $oDocument = Document::get($sDocumentId);
             if ($oDocument->isSymbolicLink()) {
                 $oDocument->switchToLinkedCore();
             }
             if (Permission::userHasDocumentReadPermission($oDocument)) {
                 if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) {
                     $this->errors[] = $oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.');
                     continue;
                 }
                 $sDocFolderId = $oDocument->getFolderID();
                 $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);
                 if ($this->bNoisy) {
                     $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
                     $oDocumentTransaction->create();
                 }
                 // fire subscription alerts for the downloaded document
                 if ($this->bNotifications) {
                     $oSubscriptionEvent = new SubscriptionEvent();
                     $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
                 }
                 $zip->addDocumentToZip($oDocument, $oFolder);
             }
         }
     }
 }
 /**
  * Subscribes the user to the document
  *
  * @author KnowledgeTree Team
  * @access public
  * @return boolean|object $result SUCCESS Boolean result of operation | FAILURE - a pear error object
  */
 public function subscribe()
 {
     if ($this->isSubscribed()) {
         return TRUE;
     }
     $subscriptionType = SubscriptionEvent::subTypes('Document');
     $user = $this->ktapi->get_user();
     $document = $this->document;
     $subscription = new Subscription($user->getId(), $document->getId(), $subscriptionType);
     $result = $subscription->create();
     if (PEAR::isError($result)) {
         return $result->getMessage();
     }
     if ($result) {
         return $result;
     }
     return $_SESSION['errorMessage'];
 }
示例#7
0
 function perform_action($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         $oDocument = $oEntity;
         if ($oDocument->isSymbolicLink()) {
             $oDocument->switchToLinkedCore();
         }
         if ($this->bNoisy) {
             $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
             $oDocumentTransaction->create();
         }
         // fire subscription alerts for the downloaded document - if global config is set
         if ($this->bNotifications) {
             $oSubscriptionEvent = new SubscriptionEvent();
             $oFolder = Folder::get($oDocument->getFolderID());
             $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
         }
         $this->oZip->addDocumentToZip($oDocument);
     } else {
         if (is_a($oEntity, 'Folder')) {
             $aDocuments = array();
             $oFolder = $oEntity;
             if ($oFolder->isSymbolicLink()) {
                 $oFolder = $oFolder->getLinkedFolder();
             }
             $sFolderId = $oFolder->getId();
             $sFolderDocs = $oFolder->getDocumentIDs($sFolderId);
             // Add folder to zip
             $this->oZip->addFolderToZip($oFolder);
             if (!empty($sFolderDocs)) {
                 $aDocuments = explode(',', $sFolderDocs);
             }
             // Get all the folders within the current folder
             $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR\n            parent_folder_ids LIKE '{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId}'";
             $aFolderList = $this->oFolder->getList($sWhereClause);
             $aLinkingFolders = $this->getLinkingEntities($aFolderList);
             $aFolderList = array_merge($aFolderList, $aLinkingFolders);
             $aFolderObjects = array();
             $aFolderObjects[$sFolderId] = $oFolder;
             // Export the folder structure to ensure the export of empty directories
             if (!empty($aFolderList)) {
                 foreach ($aFolderList as $k => $oFolderItem) {
                     if ($oFolderItem->isSymbolicLink()) {
                         $oFolderItem = $oFolderItem->getLinkedFolder();
                     }
                     if (Permission::userHasFolderReadPermission($oFolderItem)) {
                         // Get documents for each folder
                         $sFolderItemId = $oFolderItem->getID();
                         $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);
                         if (!empty($sFolderItemDocs)) {
                             $aFolderDocs = explode(',', $sFolderItemDocs);
                             $aDocuments = array_merge($aDocuments, $aFolderDocs);
                         }
                         $this->oZip->addFolderToZip($oFolderItem);
                         $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
                     }
                 }
             }
             // Add all documents to the export
             if (!empty($aDocuments)) {
                 foreach ($aDocuments as $sDocumentId) {
                     $oDocument = Document::get($sDocumentId);
                     if ($oDocument->isSymbolicLink()) {
                         $oDocument->switchToLinkedCore();
                     }
                     if (Permission::userHasDocumentReadPermission($oDocument)) {
                         if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) {
                             $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.'));
                             continue;
                         }
                         $sDocFolderId = $oDocument->getFolderID();
                         $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);
                         if ($this->bNoisy) {
                             $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
                             $oDocumentTransaction->create();
                         }
                         // fire subscription alerts for the downloaded document
                         if ($this->bNotifications) {
                             $oSubscriptionEvent = new SubscriptionEvent();
                             $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
                         }
                         $this->oZip->addDocumentToZip($oDocument, $oFolder);
                     }
                 }
             }
         }
     }
     return true;
 }
示例#8
0
 function do_notification($objects, $eventAction, $targetFolder)
 {
     // Make sure there were documents/folders affected
     if ($targetFolder && count($objects) > 0 && $eventAction != '') {
         $oSubscriptionEvent = new SubscriptionEvent();
         $oSubscriptionEvent->notifyBulkDocumentAction($objects, $eventAction, $targetFolder);
     }
 }
 function move($oDocument, $oToFolder, $oUser = null, $sReason = null)
 {
     //make sure we move the symlink, and the document it's linking to
     if ($oDocument->isSymbolicLink()) {
         $oDocument->switchToRealCore();
     } else {
         $oDocument->switchToLinkedCore();
     }
     $oFolder = $oToFolder;
     // alias.
     $oOriginalFolder = Folder::get($oDocument->getFolderId());
     $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId();
     $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId();
     if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) {
         $oDocument->setPermissionObjectId($oFolder->getPermissionObjectId());
     }
     //put the document in the new folder
     $oDocument->setFolderID($oFolder->getId());
     $sName = $oDocument->getName();
     $sFilename = $oDocument->getFileName();
     $oDocument->setFileName(KTDocumentUtil::getUniqueFilename($oToFolder, $sFilename));
     $oDocument->setName(KTDocumentUtil::getUniqueDocumentName($oToFolder, $sName));
     $res = $oDocument->update();
     if (PEAR::isError($res)) {
         return $res;
     }
     //move the document on the file system(not if it's a symlink)
     if (!$oDocument->isSymbolicLink()) {
         $oStorage =& KTStorageManagerUtil::getSingleton();
         $res = $oStorage->moveDocument($oDocument, $oFolder, $oOriginalFolder);
         if (PEAR::isError($res) || $res === false) {
             $oDocument->setFolderID($oOriginalFolder->getId());
             $res = $oDocument->update();
             if (PEAR::isError($res)) {
                 return $res;
             }
             return $res;
             // we failed, bail.
         }
     }
     $sMoveMessage = sprintf(_kt("Moved from %s/%s to %s/%s. %s"), $oOriginalFolder->getFullPath(), $oOriginalFolder->getName(), $oFolder->getFullPath(), $oFolder->getName(), $sReason);
     // create the document transaction record
     $oDocumentTransaction = new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move');
     $oDocumentTransaction->create();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument, 'old_folder' => $oOriginalFolder, 'new_folder' => $oFolder);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             return $ret;
         }
     }
     // fire subscription alerts for the moved document
     $oSubscriptionEvent = new SubscriptionEvent();
     $oSubscriptionEvent->MoveDocument($oDocument, $oFolder, $oOriginalFolder);
     return KTPermissionUtil::updatePermissionLookup($oDocument);
 }
    function do_main()
    {
        $folderName = $this->oFolder->getName();
        $this->oZip = new ZipFolder($folderName);
        if (!$this->oZip->checkConvertEncoding()) {
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        $oKTConfig =& KTConfig::getSingleton();
        $bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations");
        $bNotifications = $oKTConfig->get('export/enablenotifications', 'on') == 'on' ? true : false;
        // Get all folders and sub-folders
        $sCurrentFolderId = $this->oFolder->getId();
        $sWhereClause = "parent_folder_ids = '{$sCurrentFolderId}' OR\n        parent_folder_ids LIKE '{$sCurrentFolderId},%' OR\n        parent_folder_ids LIKE '%,{$sCurrentFolderId},%' OR\n        parent_folder_ids LIKE '%,{$sCurrentFolderId}'";
        $aFolderList = $this->oFolder->getList($sWhereClause);
        // Get any folder shortcuts within the folders
        $aLinkedFolders = KTBulkAction::getLinkingEntities($aFolderList);
        $aFolderList = array_merge($aFolderList, $aLinkedFolders);
        // Add the folders to the zip file
        $aFolderObjects = array($sCurrentFolderId => $this->oFolder);
        if (!empty($aFolderList)) {
            foreach ($aFolderList as $oFolderItem) {
                $itemId = $oFolderItem->getId();
                $linkedFolder = $oFolderItem->getLinkedFolderId();
                // If the folder has been added or is a shortcut then skip
                // The shortcut folders don't need to be added as their targets will be added.
                if (array_key_exists($itemId, $aFolderObjects) || !empty($linkedFolder)) {
                    continue;
                }
                $this->oZip->addFolderToZip($oFolderItem);
                $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
            }
        }
        // Get the list of folder ids
        $aFolderIds = array_keys($aFolderObjects);
        // Get all documents in the folder list
        $aQuery = $this->buildQuery($aFolderIds);
        $aDocumentIds = DBUtil::getResultArrayKey($aQuery, 'id');
        if (PEAR::isError($aDocumentIds)) {
            $this->addErrorMessage(_kt('There was a problem exporting the documents: ') . $aDocumentIds->getMessage());
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        // Redirect if there are no documents and no folders to export
        if (empty($aDocumentIds) && empty($aFolderList)) {
            $this->addErrorMessage(_kt("No documents found to export"));
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        $this->oPage->template = "kt3/minimal_page";
        $this->handleOutput("");
        // Add the documents to the zip file
        if (!empty($aDocumentIds)) {
            foreach ($aDocumentIds as $iId) {
                $oDocument = Document::get($iId);
                $sFolderId = $oDocument->getFolderID();
                if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) {
                    $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.'));
                    continue;
                }
                $oFolder = isset($aFolderObjects[$sFolderId]) ? $aFolderObjects[$sFolderId] : Folder::get($sFolderId);
                if ($bNoisy) {
                    $oDocumentTransaction =& new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
                    $oDocumentTransaction->create();
                }
                // fire subscription alerts for the downloaded document
                if ($bNotifications) {
                    $oSubscriptionEvent = new SubscriptionEvent();
                    $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
                }
                $this->oZip->addDocumentToZip($oDocument, $oFolder);
            }
        }
        $sExportCode = $this->oZip->createZipFile(TRUE);
        $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP()));
        $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $this->oFolder->getId(), $sExportCode));
        printf('<p>' . _kt('Your download will begin shortly. If you are not automatically redirected to your download, please click <a href="%s">here</a> ') . "</p>\n", $url);
        $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder);
        printf('<p>' . _kt('Once your download is complete, click <a href="%s">here</a> to return to the original folder') . "</p>\n", $folderurl);
        printf("</div></div></body></html>\n");
        printf('<script language="JavaScript">
                function kt_bulkexport_redirect() {
                    document.location.href = "%s";
                }
                callLater(1, kt_bulkexport_redirect);

                </script>', $url);
        exit(0);
    }