ktbulkactions.php.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 1,282 行 · 第 1/4 页

SVN-BASE
1,282
字号
            'action' => 'performaction',            'fail_action' => 'collectinfo',            'cancel_url' => $cancelUrl,            'context' => $this,        ));        $oForm-> setWidgets(array(            array('ktcore.widgets.reason',array(                'name' => 'reason',                'label' => _kt('Reason'),                'description' => _kt('Please specify why you are checking out these documents. It will assist other users in understanding why you have locked these files.'),                'value' => null,                'required' => true,                )),            array('ktcore.widgets.boolean', array(                'label' => _kt('Download Files'),                'description' => _kt('Indicate whether you would like to download these file as part of the checkout.'),                'name' => 'download_file',                'value' => true,            )),        ));        $oForm->setValidators(array(            array('ktcore.validators.string', array(                'test' => 'reason',                'max_length' => 250,                'output' => 'reason',            )),            array('ktcore.validators.boolean', array(                'test' => 'download_file',                'output' => 'download_file',            )),        ));        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() {        // 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 perform_action($oEntity) {        // checkout document        $sReason = $this->sReason;        if(is_a($oEntity, 'Document')) {            if($oEntity->getImmutable())            {            	return PEAR::raiseError($oEntity->getName() .': '. _kt('Document cannot be checked out as it is immutable'));            }            if($oEntity->getIsCheckedOut()){                $checkedOutUser = $oEntity->getCheckedOutUserID();                $sUserId = $_SESSION['userID'];                if($checkedOutUser != $sUserId){                    $oCheckedOutUser = User::get($checkedOutUser);                    return PEAR::raiseError($oEntity->getName().': '._kt('Document has already been checked out by ').$oCheckedOutUser->getName());                }            }else{                $res = KTDocumentUtil::checkout($oEntity, $sReason, $this->oUser);                if(PEAR::isError($res)) {                    return PEAR::raiseError($oEntity->getName().': '.$res->getMessage());                }            }            if($this->bDownload){                if ($this->bNoisy) {                    $oDocumentTransaction = new DocumentTransaction($oEntity, "Document part of bulk checkout", 'ktstandard.transactions.check_out', array());                    $oDocumentTransaction->create();                }                $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();                $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate');                foreach ($aTriggers as $aTrigger) {                    $sTrigger = $aTrigger[0];                    $oTrigger = new $sTrigger;                    $aInfo = array(                        'document' => $oEntity,                    );                    $oTrigger->setInfo($aInfo);                    $ret = $oTrigger->postValidate();                    if (PEAR::isError($ret)) {                        return $ret;                    }                }                $this->oZip->addDocumentToZip($oEntity);            }        }else if(is_a($oEntity, 'Folder')) {            // get documents and subfolders            $aDocuments = array();            $oFolder = $oEntity;        	if($oFolder->isSymbolicLink()){            	$oFolder = $oFolder->getLinkedFolder();            }            $sFolderId = $oFolder->getId();            $sFolderDocs = $oFolder->getDocumentIDs($sFolderId);            // get documents directly in the folder            if(!empty($sFolderDocs)){                $aDocuments = explode(',', $sFolderDocs);            }            // Get all the folders within the current folder            $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR            parent_folder_ids LIKE '{$sFolderId},%' OR            parent_folder_ids LIKE '%,{$sFolderId},%' OR            parent_folder_ids LIKE '%,{$sFolderId}'";            $aFolderList = $this->oFolder->getList($sWhereClause);			$aLinkingFolders = $this->getLinkingEntities($aFolderList);            $aFolderList = array_merge($aFolderList,$aLinkingFolders);            $aFolderObjects = array();            $aFolderObjects[$sFolderId] = $oFolder;            // Get the documents within the folder            if(!empty($aFolderList)){	                foreach($aFolderList as $k => $oFolderItem){	                	if(Permission::userHasFolderReadPermission($oFolderItem)){	                    // Get documents for each folder	              		if($oFolderItem->isSymbolicLink()){            				$oFolderItem = $oFolderItem->getLinkedFolder();            			}	                    $sFolderItemId = $oFolderItem->getID();	                    $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);	                    if(!empty($sFolderItemDocs)){	                        $aFolderDocs = explode(',', $sFolderItemDocs);	                        $aDocuments = array_merge($aDocuments, $aFolderDocs);	                    }	                    // Add the folder to the zip file	                    if($this->bDownload){	                        $this->oZip->addFolderToZip($oFolderItem);	                        $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;	                    }	                }            	}            }            // Checkout each document within the folder structure            if(!empty($aDocuments)){                foreach($aDocuments as $sDocId){                    $oDocument = Document::get($sDocId);                    if(PEAR::isError($oDocument)) {                        // add message, skip document and continue                        $this->addErrorMessage($oDocument->getName().': '.$oDocument->getMessage());                        continue;                    }               		if($oDocument->isSymbolicLink()){	    				$oDocument->switchToLinkedCore();	    			}                    if($oDocument->getImmutable())                    {                    	$this->addErrorMessage($oDocument->getName() .': '. _kt('Document cannot be checked out as it is immutable'));                    	continue;                    }                    // Check if the action is restricted by workflow on the document                    if(!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.checkout')){                        $this->addErrorMessage($oDocument->getName().': '._kt('Checkout is restricted by the workflow state.'));                        continue;                    }                    // Check if document is already checked out, check the owner.                    // If the current user is the owner, then include to the download, otherwise ignore.                    if($oDocument->getIsCheckedOut()){                        $checkedOutUser = $oDocument->getCheckedOutUserID();                        $sUserId = $_SESSION['userID'];                        if($checkedOutUser != $sUserId){                            $oCheckedOutUser = User::get($checkedOutUser);                            $this->addErrorMessage($oDocument->getName().': '._kt('Document has already been checked out by ').$oCheckedOutUser->getName());                            continue;                        }                    }else{                        // Check out document                        $res = KTDocumentUtil::checkout($oDocument, $sReason, $this->oUser);                        if(PEAR::isError($res)) {                            $this->addErrorMessage($oDocument->getName().': '._kt('Document could not be checked out. ').$res->getMessage());                            continue;                        }                    }                    // Add document to the zip file                    if($this->bDownload){                        if ($this->bNoisy) {                            $oDocumentTransaction = new DocumentTransaction($oDocument, 'Document part of bulk checkout', 'ktstandard.transactions.check_out', array());                            $oDocumentTransaction->create();                        }                        $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();                        $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate');                        foreach ($aTriggers as $aTrigger) {                            $sTrigger = $aTrigger[0];                            $oTrigger = new $sTrigger;                            $aInfo = array(                                'document' => $oDocument,                            );                            $oTrigger->setInfo($aInfo);                            $ret = $oTrigger->postValidate();                            if (PEAR::isError($ret)) {                                return $ret;                            }                        }                        $sDocFolderId = $oDocument->getFolderID();                        $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);                        $this->oZip->addDocumentToZip($oDocument, $oFolder);                    }                }            }        }        return true;    }    function do_downloadZipFile() {        $sCode = $this->oValidator->validateString($_REQUEST['exportcode']);        $folderName = $this->oFolder->getName();        $this->oZip = new ZipFolder($folderName);        $res = $this->oZip->downloadZipFile($sCode);        if(PEAR::isError($res)){            $this->addErrorMessage($res->getMessage());            redirect(generateControllerUrl("browse", "fBrowseType=folder&fFolderId=" . $this->oFolder->getId()));        }        exit(0);    }}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?