sFriendlyName = _kt('Bulk Export Plugin'); return $res; } function setup() { $this->registerAction('folderaction', 'KTBulkExportAction', 'ktstandard.bulkexport.action'); } } require_once(KT_LIB_DIR . '/actions/folderaction.inc.php'); class KTBulkExportAction extends KTFolderAction { var $sName = 'ktstandard.bulkexport.action'; var $sPermissionName = "ktcore.permissions.read"; var $_sShowPermission = "ktcore.permissions.read"; function getDisplayName() { return _kt('Bulk Export'); } function do_main() { $folderName = $this->oFolder->getName(); $this->oZip = new ZipFolder($folderName); if(!$this->oZip->checkConvertEncoding()) { redirect(KTBrowseUtil::getUrlForFolder($oFolder)); exit(0); } $oStorage =& KTStorageManagerUtil::getSingleton(); $aQuery = $this->buildQuery(); $this->oValidator->notError($aQuery); $aDocumentIds = DBUtil::getResultArrayKey($aQuery, 'id'); /* Modified 07/09/2007 by megan_w */ // Get all the folders within the current folder $sCurrentFolderId = $this->oFolder->getId(); $sWhereClause = "parent_folder_ids = '{$sCurrentFolderId}' OR parent_folder_ids LIKE '{$sCurrentFolderId},%' OR parent_folder_ids LIKE '%,{$sCurrentFolderId},%' OR parent_folder_ids LIKE '%,{$sCurrentFolderId}'"; $aFolderList = $this->oFolder->getList($sWhereClause); /* End modified */ $this->startTransaction(); $oKTConfig =& KTConfig::getSingleton(); $bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations"); $bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false; // 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($oFolder)); exit(0); } $this->oPage->requireJSResource('thirdpartyjs/MochiKit/Base.js'); $this->oPage->requireJSResource('thirdpartyjs/MochiKit/Async.js'); $this->oPage->template = "kt3/minimal_page"; $this->handleOutput(""); if(!empty($aDocumentIds)){ foreach ($aDocumentIds as $iId) { $oDocument = Document::get($iId); 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(); $oFolder = Folder::get($oDocument->getFolderID()); $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder); } $this->oZip->addDocumentToZip($oDocument); } } // Export the folder structure to ensure the export of empty directories foreach($aFolderList as $k => $oFolderItem){ $this->oZip->addFolderToZip($oFolderItem); } $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('
' . _kt('Go here to download the zip file if you are not automatically redirected there') . "
\n", $url); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); printf('' . _kt('Once downloaded, return to the original folder') . "
\n", $folderurl); printf("