setOptions(array( 'identifier' => 'ktcore.actions.bulk.delete.form', 'label' => _kt('Delete Items'), 'submit_label' => _kt('Delete'), 'action' => 'performaction', 'fail_action' => 'collectinfo', 'cancel_action' => 'main', 'context' => $this, )); $oForm->setWidgets(array( array('ktcore.widgets.reason',array( 'name' => 'reason', 'label' => _kt('Reason'), 'description' => _kt('The reason for the deletion of these documents and folders for historical purposes.'), 'value' => null, 'required' => true, )), )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'reason', 'output' => 'reason', )), )); return $oForm; } // info collection step function do_collectinfo() { $this->store_lists(); $this->get_lists(); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info'); return $oTemplate->render(array('context' => $this, 'form' => $this->form_collectinfo())); } function do_performaction() { $this->store_lists(); $this->get_lists(); $oForm = $this->form_collectinfo(); $res = $oForm->validate(); if (!empty($res['errors'])) { $oForm->handleError(); } $this->res = $res['results']; return parent::do_performaction(); } function perform_action($oEntity) { $sReason = $this->res['reason']; if(is_a($oEntity, 'Document')) { $res = KTDocumentUtil::delete($oEntity, $sReason); } else if(is_a($oEntity, 'Folder')) { $res = KTFolderUtil::delete($oEntity, $this->oUser, $sReason); } return $res; } } class KTBulkMoveAction extends KTBulkAction { var $sName = 'ktcore.actions.bulk.move'; var $_sPermission = 'ktcore.permissions.write'; var $_bMutator = true; function getDisplayName() { return _kt('Move'); } function form_collectinfo() { $oForm = new KTForm; $oForm->setOptions(array( 'identifier' => 'ktcore.actions.bulk.move.form', 'label' => _kt('Move Items'), 'submit_label' => _kt('Move'), 'action' => 'performaction', 'fail_action' => 'collectinfo', 'cancel_action' => 'main', 'context' => $this, )); // Setup the collection for move display. require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php'); $collection = new AdvancedCollection(); $oCR =& KTColumnRegistry::getSingleton(); $col = $oCR->getColumn('ktcore.columns.title'); //$col->setOptions(array('qs_params'=>array('fMoveCode'=>$sMoveCode, // 'fFolderId'=>$oFolder->getId(), // 'action'=>'startMove'))); $collection->addColumn($col); $qObj = new FolderBrowseQuery($this->oFolder->iId); $exclude=array(); foreach( $this->oEntityList->aFolderIds as $folderid) { $exclude[] = $folderid+0; } $qObj->exclude_folders = $exclude; $collection->setQueryObject($qObj); $aOptions = $collection->getEnvironOptions(); $aOptions['result_url'] = KTUtil::addQueryString($_SERVER['PHP_SELF'], array('fFolderId' => $this->oFolder->iId, 'action' => 'collectinfo')); $collection->setOptions($aOptions); $oWF =& KTWidgetFactory::getSingleton(); $oWidget = $oWF->get('ktcore.widgets.collection', array('label' => _kt('Target Folder'), 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to move the documents into.'), 'required' => true, 'name' => 'fFolderId', 'broken_name' => true, 'folder_id' => $this->oFolder->iId, 'collection' => $collection)); $oForm->addInitializedWidget($oWidget); $oForm->addWidget( array('ktcore.widgets.reason',array( 'name' => 'reason', 'label' => _kt('Reason'), 'description' => _kt('The reason for moving these documents and folders, for historical purposes.'), 'value' => null, 'required' => true, ) )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'reason', 'output' => 'reason', )), )); return $oForm; } function check_entity($oEntity) { if(is_a($oEntity, 'Document')) { if(!KTDocumentUtil::canBeMoved($oEntity)) { return PEAR::raiseError(_kt('Document cannot be moved')); } } return parent::check_entity($oEntity); } // info collection step function do_collectinfo() { $this->store_lists(); $this->get_lists(); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info'); return $oTemplate->render(array('context' => $this, 'form' => $this->form_collectinfo())); } function do_performaction() { $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->iTargetFolderId = $_REQUEST['data']['fFolderId']; $this->oTargetFolder = Folder::get($this->iTargetFolderId); $_REQUEST['fReturnData'] = ''; $_REQUEST['fFolderId'] = $this->iTargetFolderId; // does it exists if(PEAR::isError($this->oTargetFolder)) { return PEAR::raiseError(_kt('Invalid target folder selected')); } // does the user have write permission if(!Permission::userHasFolderWritePermission($this->oTargetFolder)) { $this->errorRedirectTo('collectinfo', _kt('You do not have permission to move items to this location')); } return parent::do_performaction(); } function perform_action($oEntity) { if(is_a($oEntity, 'Document')) { return KTDocumentUtil::move($oEntity, $this->oTargetFolder, $this->oUser, $this->sReason); } else if(is_a($oEntity, 'Folder')) { return KTFolderUtil::move($oEntity, $this->oTargetFolder, $this->oUser, $this->sReason); } } } class KTBulkCopyAction extends KTBulkAction { var $sName = 'ktcore.actions.bulk.copy'; var $_sPermission = 'ktcore.permissions.read'; var $_bMutator = true; function getDisplayName() { return _kt('Copy'); } function form_collectinfo() { $oForm = new KTForm; $oForm->setOptions(array( 'identifier' => 'ktcore.actions.bulk.copy.form', 'label' => _kt('Copy Items'), 'submit_label' => _kt('Copy'), 'action' => 'performaction', 'fail_action' => 'collectinfo', 'cancel_action' => 'main', 'context' => $this, )); // Setup the collection for move display. require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php'); $collection = new AdvancedCollection(); $oCR =& KTColumnRegistry::getSingleton(); $col = $oCR->getColumn('ktcore.columns.title'); //$col->setOptions(array('qs_params'=>array('fMoveCode'=>$sMoveCode, // 'fFolderId'=>$oFolder->getId(), // 'action'=>'startMove'))); $collection->addColumn($col); $qObj = new FolderBrowseQuery($this->oFolder->iId); $exclude=array(); foreach( $this->oEntityList->aFolderIds as $folderid) { $exclude[] = $folderid+0; } $qObj->exclude_folders = $exclude; $collection->setQueryObject($qObj); $aOptions = $collection->getEnvironOptions(); $aOptions['result_url'] = KTUtil::addQueryString($_SERVER['PHP_SELF'], array('fFolderId' => $this->oFolder->iId, 'action' => 'collectinfo')); $collection->setOptions($aOptions); $oWF =& KTWidgetFactory::getSingleton(); $oWidget = $oWF->get('ktcore.widgets.collection', array('label' => _kt('Target Folder'), 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to copy the documents into.'), 'required' => true, 'name' => 'fFolderId', 'broken_name' => true, 'folder_id' => $this->oFolder->iId, 'collection' => $collection)); $oForm->addInitializedWidget($oWidget); $oForm->addWidget( array('ktcore.widgets.reason',array( 'name' => 'reason', 'label' => _kt('Reason'), 'description' => _kt('The reason for copying these documents and folders, for historical purposes.'), 'value' => null, 'required' => true, ) )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'reason', 'output' => 'reason', )), )); return $oForm; } function check_entity($oEntity) { if(is_a($oEntity, 'Document')) { if(!KTDocumentUtil::canBeMoved($oEntity)) { return PEAR::raiseError(_kt('Document cannot be copied')); } } return parent::check_entity($oEntity); } // info collection step function do_collectinfo() { $this->store_lists(); $this->get_lists(); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info'); return $oTemplate->render(array('context' => $this, 'form' => $this->form_collectinfo())); } function do_performaction() { $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->iTargetFolderId = $_REQUEST['data']['fFolderId']; $this->oTargetFolder = Folder::get($this->iTargetFolderId); $_REQUEST['fReturnData'] = ''; $_REQUEST['fFolderId'] = $this->iTargetFolderId; // does it exists if(PEAR::isError($this->oTargetFolder)) { return PEAR::raiseError(_kt('Invalid target folder selected')); } // does the user have write permission if(!Permission::userHasFolderWritePermission($this->oTargetFolder)) { $this->errorRedirectTo('collectinfo', _kt('You do not have permission to move items to this location')); } return parent::do_performaction(); } function perform_action($oEntity) { if(is_a($oEntity, 'Document')) { return KTDocumentUtil::copy($oEntity, $this->oTargetFolder, $this->sReason); } else if(is_a($oEntity, 'Folder')) { return KTFolderUtil::copy($oEntity, $this->oTargetFolder, $this->oUser, $this->sReason); } } } class KTBulkArchiveAction extends KTBulkAction { var $sName = 'ktcore.actions.bulk.archive'; var $_sPermission = 'ktcore.permissions.write'; var $_bMutator = true; function getDisplayName() { return _kt('Archive'); } function form_collectinfo() { $oForm = new KTForm; $oForm->setOptions(array( 'identifier' => 'ktcore.actions.bulk.archive.form', 'label' => _kt('Archive Items'), 'submit_label' => _kt('Archive'), 'action' => 'performaction', 'fail_action' => 'collectinfo', 'cancel_action' => 'main', 'context' => $this, )); $oForm->addWidget( array('ktcore.widgets.reason',array( 'name' => 'reason', 'label' => _kt('Reason'), 'description' => _kt('The reason for archiving these documents and folders, for historical purposes.'), 'value' => null, 'required' => true, ) )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'reason', 'output' => 'reason', )), )); return $oForm; } function check_entity($oEntity) { if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) { return PEAR::raiseError(_kt('Document cannot be archived')); } return parent::check_entity($oEntity); } // info collection step function do_collectinfo() { $this->store_lists(); $this->get_lists(); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info'); return $oTemplate->render(array('context' => $this, 'form' => $this->form_collectinfo())); } function do_performaction() { $this->store_lists(); $this->get_lists(); $oForm = $this->form_collectinfo(); $res = $oForm->validate(); if (!empty($res['errors'])) { $oForm->handleError(); } $this->sReason = $_REQUEST['data']['reason']; return parent::do_performaction(); } function perform_action($oEntity) { if(is_a($oEntity, 'Document')) { $res = KTDocumentUtil::archive($oEntity, $this->sReason); if(PEAR::isError($res)){ return $res; } return true; }else if(is_a($oEntity, 'Folder')) { $aDocuments = array(); $aChildFolders = array(); $oFolder = $oEntity; // Get folder id $sFolderId = $oFolder->getID(); // Get documents in folder $sDocuments = $oFolder->getDocumentIDs($sFolderId); $aDocuments = explode(',', $sDocuments); // Get all the folders within the folder $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR parent_folder_ids LIKE '{$sFolderId},%' OR parent_folder_ids LIKE '%,{$sFolderId},%' OR parent_folder_ids LIKE '%,{$sFolderId}'"; $aChildFolders = $this->oFolder->getList($sWhereClause); // Loop through folders and get documents if(!empty($aChildFolders)){ foreach($aChildFolders as $oChild){ $sChildId = $oChild->getID(); $sChildDocs = $oChild->getDocumentIDs($sChildId); if (PEAR::isError($res)) { return false; } if(!empty($sChildDocs)){ $aChildDocs = explode(',', $sChildDocs); $aDocuments = array_merge($aDocuments, $aChildDocs); } } } // Archive all documents if(!empty($aDocuments)){ foreach($aDocuments as $sDocumentId){ $oDocument = Document::get($sDocumentId); $res = KTDocumentUtil::archive($oEntity, $this->sReason); if(PEAR::isError($res)){ return $res; } } } return true; } } } class KTBrowseBulkExportAction extends KTBulkAction { var $sName = 'ktcore.actions.bulk.export'; var $_sPermission = 'ktcore.permissions.read'; var $_bMutator = true; var $bNotifications = true; function getDisplayName() { return _kt('Export'); } function check_entity($oEntity) { if((!is_a($oEntity, 'Document')) && (!is_a($oEntity, 'Folder'))) { return PEAR::raiseError(_kt('Document cannot be exported')); } return parent::check_entity($oEntity); } function do_performaction() { $folderName = $this->oFolder->getName(); $this->oZip = new ZipFolder($folderName); $res = $this->oZip->checkConvertEncoding(); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); $sReturn = sprintf('
' . _kt('Return to the original folder') . "
\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('' . _kt('Go here to download the zip file if you are not automatically redirected there') . "
\n", $url); $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder); $str .= sprintf('' . _kt('Once downloaded, return to the original folder') . "
\n", $folderurl); //$str .= sprintf("