function form_main() { $oForm = new KTForm(); $oForm->setOptions(array('context' => &$this, 'identifier' => 'ktcore.folder.add', 'action' => 'addFolder', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForFolder($this->oFolder), 'label' => _kt('Add a folder'), 'submit_label' => _kt('Add Folder'), 'extraargs' => $this->meldPersistQuery("", "", true))); // widgets $oForm->setWidgets(array(array('ktcore.widgets.string', array('label' => _kt('Folder name'), 'description' => _kt('The name for the new folder.'), 'required' => true, 'name' => 'name')))); // Electronic Signature if enabled global $default; if ($default->enableESignatures) { $oForm->addWidget(array('ktcore.widgets.info', array('label' => _kt('This action requires authentication'), 'description' => _kt('Please provide your user credentials as confirmation of this action.'), 'name' => 'info'))); $oForm->addWidget(array('ktcore.widgets.string', array('label' => _kt('Username'), 'name' => 'sign_username', 'required' => true))); $oForm->addWidget(array('ktcore.widgets.password', array('label' => _kt('Password'), 'name' => 'sign_password', 'required' => true))); $oForm->addWidget(array('ktcore.widgets.reason', array('label' => _kt('Reason'), 'description' => _kt('Please specify why you are checking out this document. It will assist other users in understanding why you have locked this file. Please bear in mind that you can use a maximum of <strong>250</strong> characters.'), 'name' => 'reason'))); } $oForm->setValidators(array(array('ktcore.validators.string', array('test' => 'name', 'output' => 'name')), array('ktcore.validators.illegal_char', array('test' => 'name', 'output' => 'name')))); if ($default->enableESignatures) { $oForm->addValidator(array('electonic.signatures.validators.authenticate', array('object_id' => $this->oFolder->getId(), 'type' => 'folder', 'action' => 'ktcore.transactions.add_folder', 'test' => 'info', 'output' => 'info'))); } return $oForm; }
function do_rename() { $aErrorOptions = array('redirect_to' => array('', sprintf('fFolderId=%d', $this->oFolder->getId()))); $sFolderName = KTUtil::arrayGet($_REQUEST, 'foldername'); $aErrorOptions['defaultmessage'] = _kt("No folder name given"); $sFolderName = $this->oValidator->validateString($sFolderName, $aErrorOptions); $sFolderName = $this->oValidator->validateIllegalCharacters($sFolderName, $aErrorOptions); $sOldFolderName = $this->oFolder->getName(); if ($this->oFolder->getId() != 1) { $oParentFolder =& Folder::get($this->oFolder->getParentID()); if (PEAR::isError($oParentFolder)) { $this->errorRedirectToMain(_kt('Unable to retrieve parent folder.'), $aErrorOptions['redirect_to'][1]); exit(0); } if (KTFolderUtil::exists($oParentFolder, $sFolderName)) { $this->errorRedirectToMain(_kt('A folder with that name already exists.'), $aErrorOptions['redirect_to'][1]); exit(0); } } $res = KTFolderUtil::rename($this->oFolder, $sFolderName, $this->oUser); if (PEAR::isError($res)) { $_SESSION['KTErrorMessage'][] = $res->getMessage(); redirect(KTBrowseUtil::getUrlForFolder($this->oFolder)); exit(0); } else { $_SESSION['KTInfoMessage'][] = sprintf(_kt('Folder "%s" renamed to "%s".'), $sOldFolderName, $sFolderName); } $this->commitTransaction(); redirect(KTBrowseUtil::getUrlForFolder($this->oFolder)); exit(0); }
function do_request($oDocument) { // Display form for sending a request through the the sys admin to unarchive the document // name, document, request, submit $oForm = new KTForm(); $oForm->setOptions(array('label' => _kt('Request restoration of document'), 'submit_label' => _kt('Send request'), 'identifier' => '', 'cancel_url' => KTBrowseUtil::getUrlForFolder($oFolder), 'fail_action' => 'main', 'context' => $this)); $oForm->addWidget(array('ktcore.widgets.text', array('label' => _kt('Reason'), 'name' => 'reason', 'required' => true))); $data = isset($_REQUEST['data']) ? $_REQUEST['data'] : array(); $iFolderId = $oDocument->getFolderID(); $oFolder = Folder::get($iFolderId); $sFolderUrl = KTBrowseUtil::getUrlForFolder($oFolder); if (!empty($data)) { $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError('', $aError); } $aAdminGroups = Group::getAdministratorGroups(); if (!PEAR::isError($aAdminGroups) && !empty($aAdminGroups)) { foreach ($aAdminGroups as $oGroup) { $aGroupUsers = $oGroup->getMembers(); // ensure unique users foreach ($aGroupUsers as $oUser) { $aUsers[$oUser->getId()] = $oUser; } } $sSubject = _kt('Request for an archived document to be restored'); $sDetails = $data['reason']; // Send request foreach ($aUsers as $oU) { if (!PEAR::isError($oU)) { include_once KT_DIR . '/plugins/ktcore/KTAssist.php'; KTAssistNotification::newNotificationForDocument($oDocument, $oU, $this->oUser, $sSubject, $sDetails); } } // Redirect to folder $this->addInfoMessage(_kt('The System Administrators have been notified of your request.')); redirect($sFolderUrl); exit; } } return $oForm->renderPage(_kt('Archived document request') . ': ' . $oDocument->getName()); }
function getConfigDescription() { if (!$this->isLoaded()) { return _kt('This trigger has no configuration.'); } // the actual permissions are stored in the array. $perms = array(); if (empty($this->aConfig) || is_null($this->aConfig['folder_id'])) { return _kt('<strong>This transition cannot be performed: no folder has been selected.</strong>'); } $oFolder = Folder::get($this->aConfig['folder_id']); if (PEAR::isError($oFolder)) { return _kt('<strong>The folder required for this trigger has been deleted, so the transition cannot be performed.</strong>'); } else { if ($this->isCopy) { return sprintf(_kt('The document will be copied to folder "<a href="%s">%s</a>".'), KTBrowseUtil::getUrlForFolder($oFolder), htmlentities($oFolder->getName(), ENT_NOQUOTES, 'UTF-8')); } else { return sprintf(_kt('The document will be moved to folder "<a href="%s">%s</a>".'), KTBrowseUtil::getUrlForFolder($oFolder), htmlentities($oFolder->getName(), ENT_NOQUOTES, 'UTF-8')); } } }
function buildFolderLink($aDataRow) { if (is_null(KTUtil::arrayGet($this->aOptions, 'direct_folder'))) { return KTUtil::addQueryStringSelf('fFolderId=' . $aDataRow['folder']->getId()); } else { return KTBrowseUtil::getUrlForFolder($aDataRow['folder']); } }
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_performaction() { // Get reason for checkout & check if docs must be downloaded $this->store_lists(); $this->get_lists(); $oForm = $this->form_collectinfo(); $res = $oForm->validate(); if (!empty($res['errors'])) { $oForm->handleError(); } $this->sReason = $_REQUEST['data']['reason']; $this->bDownload = $_REQUEST['data']['download_file']; $oKTConfig =& KTConfig::getSingleton(); $this->bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations"); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); $sReturn = sprintf('<p>' . _kt('Return to the original <a href="%s">folder</a>') . "</p>\n", $folderurl); $this->startTransaction(); // if files are to be downloaded - create the temp directory for the bulk export if ($this->bDownload) { $folderName = $this->oFolder->getName(); $this->oZip = new ZipFolder($folderName); $res = $this->oZip->checkConvertEncoding(); if (PEAR::isError($res)) { $this->addErrorMessage($res->getMessage()); return $sReturn; } } $result = parent::do_performaction(); if (PEAR::isError($result)) { $this->addErrorMessage($result->getMessage()); return $sReturn; } if ($this->bDownload) { $sExportCode = $this->oZip->createZipFile(); if (PEAR::isError($sExportCode)) { $this->addErrorMessage($sExportCode->getMessage()); return $sReturn; } } $this->commitTransaction(); if ($this->bDownload) { $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $this->oFolder->getId(), $sExportCode)); $str = sprintf('<p>' . _kt('Go <a href="%s">here</a> to download the zip file if you are not automatically redirected there') . "</p>\n", $url); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); $str .= sprintf('<p>' . _kt('Once downloaded, return to the original <a href="%s">folder</a>') . "</p>\n", $folderurl); $str .= sprintf("</div></div></body></html>\n"); $str .= sprintf('<script language="JavaScript"> function kt_bulkexport_redirect() { document.location.href = "%s"; } callLater(1, kt_bulkexport_redirect); </script>', $url); return $str; } return $result; }
function getUrlForFolder($params, &$smarty) { return KTBrowseUtil::getUrlForFolder($params['folder']); }
function renderData($aDataRow) { // only _ever_ show this for documents. if ($aDataRow["type"] === "folder") { return ' '; } $link = KTBrowseUtil::getUrlForFolder($aDataRow['document']->getFolderId()); return sprintf('<a href="%s" class="ktAction ktMoveUp" title="%s">%s</a>', $link, _kt('View Folder'), _kt('View Folder')); }
function getBulkReturnUrl() { $sReturnAction = $_REQUEST['fReturnAction']; $sReturnData = $_REQUEST['fReturnData']; $sAction = 'main'; $qs = ''; switch ($sReturnAction) { case 'browse': $sReturnData = empty($sReturnData) ? $_REQUEST['fFolderId'] : $sReturnData; $sTargetUrl = KTBrowseUtil::getUrlForFolder(Folder::get($sReturnData)); break; case 'simpleSearch': $sTargetUrl = KTBrowseUtil::getSimpleSearchBaseUrl(); $extra = 'fSearchableText=' . $sReturnData; break; case 'booleanSearch': $sTargetUrl = KTBrowseUtil::getBooleanSearchBaseUrl(); $sAction = 'performSearch'; $extra = 'boolean_search_id=' . $sReturnData; break; case 'search2': $sTargetUrl = KTBrowseUtil::getSearchResultURL(); $sAction = 'searchResults'; break; default: $sTargetUrl = $sReturnAction; $sAction = ''; } $qs = !empty($sAction) ? 'action=' . $sAction : ''; $qs .= !empty($extra) ? '&' . $extra : ''; $sTargetUrl = KTUtil::addQueryString($sTargetUrl, $qs); return $sTargetUrl; }
function form_complete() { $sReturnAction = KTUtil::arrayGet($_REQUEST, 'fReturnAction'); $sReturnData = KTUtil::arrayGet($_REQUEST, 'fReturnData'); $sAction = 'main'; switch ($sReturnAction) { case 'browse': $sReturnData = empty($sReturnData) ? $_REQUEST['fFolderId'] : $sReturnData; $sTargetUrl = KTBrowseUtil::getUrlForFolder(Folder::get($sReturnData)); break; case 'simpleSearch': // do we use this? $sTargetUrl = KTBrowseUtil::getSimpleSearchBaseUrl(); $extraargs = array('fSearchableText' => $sReturnData); break; case 'booleanSearch': // do we use this? $sTargetUrl = KTBrowseUtil::getBooleanSearchBaseUrl(); $sAction = 'performSearch'; $extraargs = array('boolean_search_id' => $sReturnData); break; case 'search2': $sTargetUrl = KTBrowseUtil::getSearchResultURL(); $sAction = 'refresh'; break; default: $sTargetUrl = $sReturnAction; $sAction = ''; } $oForm = new KTForm(); $oForm->setOptions(array('identifier' => 'ktcore.actions.bulk.complete.form', 'submit_label' => _kt('Return'), 'targeturl' => $sTargetUrl, 'context' => $this, 'action' => $sAction, 'extraargs' => $extraargs, 'noframe' => true)); return $oForm; }
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); }