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; }
/** * Loop through the queue and archive the items. * * @return unknown */ public function processQueue() { global $default; // get items from queue $queue = $this->getQueue(); if (PEAR::isError($queue)) { $default->log->debug('Download Queue: error on fetching queue - ' . $queue->getMessage()); return false; } // Set queue as locked touch($this->lockFile); // Loop through items and create downloads foreach ($queue as $code => $download) { // reset the error messages $this->errors = null; // if the user_id is not set then skip if (!isset($download[0]['user_id']) || empty($download[0]['user_id'])) { $default->log->debug('Download Queue: no user id set for download code ' . $code); $error = array(_kt('No user id has been set, the archive cannot be created.')); $result = $this->setItemStatus($code, 3, $error); continue; } // Force a session for the user $_SESSION['userID'] = $download[0]['user_id']; $baseFolderId = $download[0]['folder_id']; // Create a new instance of the archival class $zip = new ZipFolder('', $code); $res = $zip->checkConvertEncoding(); if (PEAR::isError($res)) { $default->log->error('Download Queue: Archive class check convert encoding error - ' . $res->getMessage()); $error = array(_kt('The archive cannot be created. An error occurred in the encoding.')); $result = $this->setItemStatus($code, 3, $error); continue; } $result = $this->setItemStatus($code, 1); if (PEAR::isError($result)) { $default->log->error('Download Queue: item status could not be set for user: '******'userID'] . ', code: ' . $code . ', error: ' . $result->getMessage()); } $default->log->debug('Download Queue: Creating download for user: '******'userID'] . ', code: ' . $code); DBUtil::startTransaction(); // Add the individual files and folders into the archive foreach ($download as $item) { if ($item['object_type'] == 'document') { $docId = $item['object_id']; $this->addDocument($zip, $docId); } if ($item['object_type'] == 'folder') { $folderId = $item['object_id']; $this->addFolder($zip, $folderId); } } $res = $zip->createZipFile(); if (PEAR::isError($res)) { $default->log->debug('Download Queue: Archive could not be created. Exiting transaction. ' . $res->getMessage()); DBUtil::rollback(); $error = array(_kt('The archive could not be created.')); $result = $this->setItemStatus($code, 3, $error); continue; } $default->log->debug('Download Queue: Archival successful'); $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $baseFolderId, 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); if (PEAR::isError($oTransaction)) { $default->log->debug('Download Queue: transaction could not be logged. ' . $oTransaction->getMessage()); } DBUtil::commit(); // Set status for the download $this->errors['archive'] = $_SESSION['zipcompression']; $result = $this->setItemStatus($code, 2, $this->errors); if (PEAR::isError($result)) { $default->log->error('Download Queue: item status could not be set for user: '******'userID'] . ', code: ' . $code . ', error: ' . $result->getMessage()); } // reset the error messages $this->errors = null; $_SESSION['zipcompression'] = null; } // Remove lock file @unlink($this->lockFile); }
function do_performaction() { $folderName = $this->oFolder->getName(); $this->oZip = new ZipFolder($folderName); $res = $this->oZip->checkConvertEncoding(); $folderurl = $this->getReturnUrl(); $sReturn = sprintf('<p>' . _kt('Return to the original <a href="%s">folder</a>') . "</p>\n", $folderurl); if (PEAR::isError($res)) { $this->addErrorMessage($res->getMessage()); return $sReturn; } $this->startTransaction(); $oKTConfig =& KTConfig::getSingleton(); $this->bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations"); $this->bNotifications = $oKTConfig->get('export/enablenotifications', 'on') == 'on' ? true : false; $result = parent::do_performaction(); $sExportCode = $this->oZip->createZipFile(); if (PEAR::isError($sExportCode)) { $this->addErrorMessage($sExportCode->getMessage()); return $sReturn; } $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); $this->commitTransaction(); $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $this->oFolder->getId(), $sExportCode)); $str = sprintf('<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); $str .= sprintf('<p>' . _kt('Once your download is complete, click <a href="%s">here</a> to return to the original folder') . "</p>\n", $folderurl); //$str .= sprintf("</div></div></body></html>\n"); $str .= sprintf('<script language="JavaScript"> function kt_bulkexport_redirect() { document.location.href = "%s"; } callLater(2, kt_bulkexport_redirect); </script>', $url); return $str; }
/** * Log the transaction for the current user. * * @author KnowledgeTree Team * @access protected * @param string $comment * @param string $namespace * @return object */ protected function _logTransaction($comment, $namespace) { $type = get_class($this->folderItem); $object = $this->folderItem->getObject(); $objectId = $object->getId(); switch ($type) { case 'KTAPI_Folder': KTFolderTransaction::createFromArray(array('folderid' => $objectId, 'comment' => $comment, 'transactionNS' => $namespace, 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); break; case 'KTAPI_Document': DocumentTransaction::createFromArray(array('folderid' => $objectId, 'comment' => $comment, 'transactionNS' => $namespace, 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); break; default: throw new Exception('Unexpected type: ' . $type); } return $object; }
function do_main() { $config = KTConfig::getSingleton(); $useQueue = $config->get('export/useDownloadQueue', true); // Create the export code $exportCode = KTUtil::randomString(); $this->oZip = new ZipFolder('', $exportCode); if (!$this->oZip->checkConvertEncoding()) { redirect(KTBrowseUtil::getUrlForFolder($this->oFolder)); exit(0); } $bNoisy = $config->get("tweaks/noisyBulkOperations"); $bNotifications = $config->get('export/enablenotifications', 'on') == 'on' ? true : false; $sCurrentFolderId = $this->oFolder->getId(); $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $sCurrentFolderId, $exportCode)); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); if ($useQueue) { DownloadQueue::addItem($exportCode, $sCurrentFolderId, $sCurrentFolderId, 'folder'); $task_url = KTUtil::kt_url() . '/bin/ajaxtasks/downloadTask.php'; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/action/bulk_download'); $aParams = array('folder_url' => $folderurl, 'url' => $task_url, 'code' => $exportCode, 'download_url' => $url); return $oTemplate->render($aParams); } // Get all folders and sub-folders $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())); $sReturn = '<p>' . _kt('Creating zip file. Compressing and archiving in progress ...') . '</p>'; $sReturn .= "<p style='margin-bottom: 10px;'><br /><b>" . _kt('Warning! Please wait for archiving to complete before closing the page.') . '</b><br />' . _kt('Note: Closing the page before the download link displays will cancel your Bulk Download.') . '</p>'; $sReturn .= '<p>' . _kt('Once your download is complete, click <a href="' . $folderurl . '">here</a> to return to the original folder') . "</p>\n"; print $sReturn; printf("</div></div></body></html>\n"); printf('<script language="JavaScript"> function kt_bulkexport_redirect() { document.location.href = "%s"; } callLater(2, kt_bulkexport_redirect); </script>', $url); exit(0); }
function do_removeDynamicCondition() { $aOptions = array('redirect_to' => array('main', 'fFolderId=' . $this->oFolder->getId())); if (!KTBrowseUtil::inAdminMode($this->oUser, $this->oFolder)) { $this->oValidator->userHasPermissionOnItem($this->oUser, $this->_sEditShowPermission, $this->oFolder, $aOptions); } $aOptions = array('redirect_to' => array('edit', 'fFolderId=' . $this->oFolder->getId())); $oDynamicCondition =& $this->oValidator->validateDynamicCondition($_REQUEST['fDynamicConditionId'], $aOptions); $res = $oDynamicCondition->delete(); $this->oValidator->notError($res, $aOptions); $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => _kt('Removed dynamic permissions'), '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); $oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId()); KTPermissionUtil::updatePermissionLookupForPO($oPO); $this->successRedirectTo('edit', _kt('Dynamic permission removed'), 'fFolderId=' . $this->oFolder->getId()); }
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); }
function do_setRoleGroups() { $role_allocation_id = KTUtil::arrayGet($_REQUEST, 'allocation_id'); $oRoleAllocation = RoleAllocation::get($role_allocation_id); if (PEAR::isError($oRoleAllocation) || $oRoleAllocation === false) { $this->errorRedirectToMain(_kt('No such role allocation.'), sprintf('fFolderId=%d', $this->oFolder->getId())); } $groups = KTUtil::arrayGet($_REQUEST, 'groupFinal', ''); $aGroupIds = explode(',', $groups); // check that its not corrupt.. $aFinalGroupIds = array(); foreach ($aGroupIds as $iGroupId) { $oGroup =& Group::get($iGroupId); if (!(PEAR::isError($oGroup) || $oGroup == false)) { $aFinalGroupIds[] = $iGroupId; } } if (empty($aFinalGroupIds)) { $aFinalGroupIds = null; } // hack straight in. $oPD = $oRoleAllocation->getPermissionDescriptor(); $aAllowed = $oPD->getAllowed(); // now, grab the existing allowed and modify. $aAllowed['group'] = $aFinalGroupIds; $oRoleAllocation->setAllowed($aAllowed); $res = $oRoleAllocation->update(); if (PEAR::isError($res) || $res == false) { $this->errorRedirectToMain(_kt('Failed to change the role allocation.') . print_r($res, true), sprintf('fFolderId=%d', $this->oFolder->getId())); } $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => _kt('Set role groups'), 'transactionNS' => 'ktcore.transactions.role_allocations_change', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); $aOptions = array('defaultmessage' => _kt('Problem assigning role groups'), 'redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId()))); $this->oValidator->notErrorFalse($oTransaction, $aOptions); $this->renegeratePermissionsForRole($oRoleAllocation->getRoleId()); $this->successRedirectToMain(_kt('Allocation changed.'), sprintf('fFolderId=%d', $this->oFolder->getId())); }
function do_performaction() { $config = KTConfig::getSingleton(); $useQueue = $config->get('export/useDownloadQueue', true); // Create the export code $this->sExportCode = KTUtil::randomString(); $_SESSION['exportcode'] = $this->sExportCode; // Save the return url in session so it is not lost when doing the download $folderurl = $this->getReturnUrl(); $_SESSION['export_return_url'] = $folderurl; $download_url = KTUtil::addQueryStringSelf("action=downloadZipFile&fFolderId={$this->oFolder->getId()}&exportcode={$this->sExportCode}"); if ($useQueue) { $result = parent::do_performaction(); $url = KTUtil::kt_url() . '/presentation/lookAndFeel/knowledgeTree/bulkdownload/downloadTask.php'; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/action/bulk_download'); $aParams = array('folder_url' => $folderurl, 'url' => $url, 'code' => $this->sExportCode, 'download_url' => $download_url); return $oTemplate->render($aParams); } $this->oZip = new ZipFolder('', $this->sExportCode); $res = $this->oZip->checkConvertEncoding(); if (PEAR::isError($res)) { $this->addErrorMessage($res->getMessage()); return $sReturn; } $this->startTransaction(); $result = parent::do_performaction(); $sExportCode = $this->oZip->createZipFile(); if (PEAR::isError($sExportCode)) { $this->addErrorMessage($sExportCode->getMessage()); $this->rollbackTransaction(); return $sReturn; } $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP())); $this->commitTransaction(); $str = '<p>' . _kt('Creating zip file. Compressing and archiving in progress ...') . '</p>'; $str .= "<p style='margin-bottom: 10px;'><br /><b>" . _kt('Warning! Please wait for archiving to complete before closing the page.') . '</b><br />' . _kt('Note: Closing the page before the download link displays will cancel your Bulk Download.') . '</p>'; $str .= sprintf('<p>' . _kt('Once your download is complete, click <a href="%s">here</a> to return to the original folder') . "</p>\n", $folderurl); $str .= sprintf('<script language="JavaScript"> function kt_bulkexport_redirect() { document.location.href = "%s"; } callLater(5, kt_bulkexport_redirect); </script>', $download_url); return $str; }