function display_viewlet() { $oKTTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oKTTemplating->loadTemplate("ktcore/document/viewlets/workflow"); if (is_null($oTemplate)) { return ""; } $oWorkflowState = KTWorkflowState::get($this->oDocument->getWorkflowStateId()); if (PEAR::isError($oWorkflowState)) { return ""; } $aDisplayTransitions = array(); $aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->oDocument, $this->oUser); if (empty($aTransitions)) { return ""; } // Check if the document has been checked out $bIsCheckedOut = $this->oDocument->getIsCheckedOut(); $iId = $this->oDocument->getId(); if ($bIsCheckedOut) { // If document is checked out, don't link into the workflow. $aDisplayTransitions = array(); } else { foreach ($aTransitions as $oTransition) { if (is_null($oTransition) || PEAR::isError($oTransition)) { continue; } $aDisplayTransitions[] = array('url' => KTUtil::ktLink('action.php', 'ktcore.actions.document.workflow', array("fDocumentId" => $iId, "action" => "quicktransition", "fTransitionId" => $oTransition->getId())), 'name' => $oTransition->getName()); } } //Retreive the comment for the previous transition $aCommentQuery = array("SELECT comment FROM document_transactions\n where transaction_namespace='ktcore.transactions.workflow_state_transition'\n AND document_id = ?\n ORDER BY id DESC LIMIT 1;"); $aCommentQuery[] = array($iId); $aTransitionComments = DBUtil::getResultArray($aCommentQuery); $oLatestTransitionComment = null; if (!empty($aTransitionComments)) { $aRow = $aTransitionComments[0]; $oLatestTransitionComment = $aRow['comment']; $iCommentPosition = strpos($oLatestTransitionComment, ':'); //comment found after first colon in string if ($iCommentPosition > 0) { $oLatestTransitionComment = substr($oLatestTransitionComment, $iCommentPosition + 2, strlen($oLatestTransitionComment) - $iCommentPosition); } else { $oLatestTransitionComment = null; } } $oTemplate->setData(array('context' => $this, 'bIsCheckedOut' => $bIsCheckedOut, 'transitions' => $aDisplayTransitions, 'state_name' => $oWorkflowState->getName(), 'comment' => $oLatestTransitionComment)); return $oTemplate->render(); }
/** * Dispatch function */ function do_main() { $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Task Scheduler Management')); $this->oPage->setTitle(_kt('Task Scheduler Management')); $this->oPage->requireJSResource('resources/js/scheduler.js'); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/scheduler'); // Link for clearing out old tasks // $lClear = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=clearTasks'); // $sClear = "<a href='#' onclick='javascript: clearTasks(\"{$lClear}\");'>"._kt('Clean-up old tasks').'</a>'; // Link for saving the updated frequencies $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=saveFreq'); // Get all tasks $aList = SchedulerEntity::getTaskList(); $aHeadings = array(' ', _kt('Task'), _kt('Frequency'), _kt('Next run time'), _kt('Previous run time'), _kt('Time taken to complete'), ' '); //$aFrequencies = array('monthly', 'weekly', 'daily', 'hourly', 'half_hourly', 'quarter_hourly', '10mins', '5mins'); $aFrequencies = array('monthly' => _kt('monthly'), 'weekly' => _kt('weekly'), 'daily' => _kt('daily'), 'hourly' => _kt('hourly'), 'half_hourly' => _kt('every half hour'), 'quarter_hourly' => _kt('every quarter hour'), '10mins' => _kt('every 10 minutes'), '5mins' => _kt('every 5 minutes'), '1min' => _kt('every minute'), '30secs' => _kt('every 30 seconds')); $aTemplateData = array('context' => $this, 'aList' => $aList, 'aHeadings' => $aHeadings, 'aFrequencies' => $aFrequencies, 'i' => 1, 'sUrl' => $sUrl); return $oTemplate->render($aTemplateData); }
/** * Display the metadata comparison * */ function do_viewComparison() { // this is just a redirector $QS = array('action' => 'viewComparison', 'fDocumentId' => $this->oDocument->getId(), 'fBaseVersion' => $_REQUEST['fBaseVersion'], 'fComparisonVersion' => $_REQUEST['fComparisonVersion']); $frag = array(); foreach ($QS as $k => $v) { $frag[] = sprintf('%s=%s', urlencode($k), urlencode($v)); } redirect(KTUtil::ktLink('view.php', null, implode('&', $frag))); }
function getHelpURL() { if (empty($this->helpPage)) { return null; } return KTUtil::ktLink('help.php', $this->helpPage); }
/** * Run the task on the next iteration */ function getStatusLink() { $sId = $this->getId(); $sStatus = $this->getStatus(); if ($sStatus == 'system') { return ''; } $sDisableText = _kt('Disable Task'); $sEnableText = _kt('Enable Task'); $sLinkText = $sStatus == 'enabled' ? $sDisableText : $sEnableText; $sUrl = KTUtil::ktLink('admin.php', 'misc/scheduler', 'action=updateStatus'); $sLink = "<input type='button' id='statusLink{$this->getId()}'\n onclick='javascript: toggleStatus(\"{$sId}\", \"{$sUrl}\", \"{$sDisableText}\", \"{$sEnableText}\");' value='{$sLinkText}' />"; return $sLink; }
function permissionDenied() { // handle anonymous specially. if ($this->oUser->getId() == -2) { redirect(KTUtil::ktLink('login.php', '', sprintf("redirect=%s&errorMessage=%s", urlencode($_SERVER['REQUEST_URI']), urlencode(_kt("You must be logged in to perform this action"))))); exit(0); } global $default; $msg = '<h2>' . _kt('Permission Denied') . '</h2>'; $msg .= '<p>' . _kt('If you feel that this is incorrect, please report both the action and your username to a system administrator.') . '</p>'; $this->oPage->setPageContents($msg); $this->oPage->setUser($this->oUser); $this->oPage->hideSection(); $this->oPage->render(); exit(0); }
function renderData($aDataRow) { $localname = $this->name; // only _ever_ show this folder documents. if ($aDataRow['type'] === 'folder') { return ' '; } // FIXME at some point we may want to hide this if the user doens't have the download action, but its OK for now. $link = KTUtil::ktLink('action.php', 'ktcore.actions.document.view', 'fDocumentId=' . $aDataRow['document']->getId()); $outStr = sprintf('<a href="%s" class="ktAction ktDownload" title="%s">%s</a>', $link, _kt('Download Document'), _kt('Download Document')); return $outStr; }
function render() { $bWin = false; if (OS_WINDOWS) { $bWin = true; } $aTimes = schedulerDashlet::getRunTimes(); $sLastTime = $aTimes['lasttime']; $sTimeDif = $aTimes['timedif']; $bDue = $aTimes['due']; $oKTConfig =& KTConfig::getSingleton(); $rootUrl = $oKTConfig->get("rootUrl"); if ($oKTConfig->get("ui/morphEnabled") == '1') { $sImg = $rootUrl . '/skins/kts_' . $oKTConfig->get("ui/morphTo"); } else { $sImg = $rootUrl . '/resources/graphics'; } $sImgPlus = $sImg . '/bullet_toggle_plus.png'; $sImgMinus = $sImg . '/bullet_toggle_minus.png'; $sPath = KT_DIR . '/bin/scheduler.php'; $sOnClick = " var cron = document.getElementById('cronguide');\n var icon = document.getElementById('scheduler_icon');\n if(cron.style.visibility == 'hidden'){\n cron.style.visibility = 'visible'; cron.style.display = 'block';\n icon.src = '{$sImgMinus}';\n }else{\n cron.style.visibility = 'hidden'; cron.style.display = 'none';\n icon.src = '{$sImgPlus}';\n }"; $sAdmin = KTUtil::ktLink('admin.php', 'misc/scheduler'); $sAdminLink = "<a href='{$sAdmin}'>" . _kt('Administration page') . '</a>'; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/dashlets/scheduler'); $aTemplateData = array('lasttime' => $sLastTime, 'timedif' => $sTimeDif, 'isDue' => $bDue, 'bWin' => $bWin, 'sPath' => $sPath, 'sAdminLink' => $sAdminLink, 'sImg' => $sImgPlus, 'onClick' => $sOnClick); return $oTemplate->render($aTemplateData); }
function do_selectType() { switch ($_REQUEST[data][convert_type]) { case '0': $this->do_pdfdownload(); break; case '1': $this->do_pdfduplicate(); break; case '2': $this->do_pdfreplace(); break; default: $this->do_pdfdownload(); } redirect(KTUtil::ktLink('action.php', 'ktstandard.pdf.generate', array("fDocumentId" => $this->oDocument->getId()))); exit(0); }
function do_viewCategory() { // are we categorised, or not? $category = KTUtil::arrayGet($_REQUEST, 'fCategory', $this->category); //Removing bad documents/fieldmanagement links from the Document Metadata and Workflow Configuration page. if ($category == 'documents') { $oPage =& $GLOBALS['main']; $aJavascript[] = 'thirdpartyjs/jquery/jquery-1.3.2.js'; $oPage->requireJSResources($aJavascript); $jscript .= "<script src='resources/js/kt_hideadminlink.js' type='text/javascript'></script>"; } $oRegistry =& KTAdminNavigationRegistry::getSingleton(); $aCategory = $oRegistry->getCategory($category); $aItems = $oRegistry->getItemsForCategory($category); asort($aItems); $this->aBreadcrumbs[] = array('name' => $aCategory['title'], 'url' => KTUtil::ktLink('admin.php', $category)); $this->oPage->title = _kt('Administration') . ': ' . $aCategory['title']; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('kt3/admin_items'); $aTemplateData = array('context' => $this, 'category' => $aCategory, 'items' => $aItems, 'baseurl' => $_SERVER['PHP_SELF'], 'jscript' => $jscript); return $oTemplate->render($aTemplateData); }
function ktLink($params, &$smarty) { return KTUtil::ktLink($params['base'], $params['subpath'], $params['query']); }
function renderData($aDataRow) { // only _ever_ show this for documents. if ($aDataRow["type"] === "folder") { return ' '; } $link = KTUtil::ktLink('action.php', 'ktcore.actions.document.view', 'fDocumentId=' . $aDataRow['document']->getId()); return sprintf('<a href="%s" class="ktAction ktDownload" title="%s">%s</a>', $link, _kt('Download Document'), _kt('Download Document')); }
function do_editComplexFieldset() { $fieldset_id = KTUtil::arrayGet($_REQUEST, "fieldset_id"); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/conditional/editcomplex"); /* alright: to "do" this we need at least: * 1. the list of all the columns (id, name) and their available values. * 2. the fieldset_id. * we can then render in/out. Everything "intelligent" happens * in AJAX (doing it with submits sucks arse. * * FIXME we fake it here with nested arrays... */ $oFieldset =& KTFieldset::get($fieldset_id); $aFields =& $oFieldset->getFields(); $this->aBreadcrumbs[] = array('url' => KTUtil::ktLink('admin.php', 'documents/fieldmanagement', 'action=edit&fFieldsetId=' . $oFieldset->getId()), 'name' => $oFieldset->getName()); $this->aBreadcrumbs[] = array('url' => KTUtil::ktLink('admin.php', 'documents/fieldmanagement', 'action=manageConditional&fFieldsetId=' . $oFieldset->getId()), 'name' => _kt('Manage conditional fieldset')); $sTable = KTUtil::getTableName('field_orders'); $aQuery = array("SELECT parent_field_id, child_field_id FROM {$sTable} WHERE fieldset_id = ?", array($oFieldset->getId())); $aFieldOrders = DBUtil::getResultArray($aQuery); $aOrders = array(); foreach ($aFieldOrders as $row) { $aChildren = KTUtil::arrayGet($aOrders, $row['parent_field_id'], array()); $aChildren[] = $row['child_field_id']; $aOrders[$row['parent_field_id']] = $aChildren; } $aKeyedFields = array(); $aOrderedFields = array(); $aStack = array($oFieldset->getMasterFieldId()); // first, key foreach ($aFields as $oField) { $aKeyedFields[$oField->getId()] = $oField; } while (!empty($aStack)) { $iKey = array_shift($aStack); // this shouldn't happen, but avoid it anyway. if (!is_null($aKeyedFields[$iKey])) { $aOrderedFields[] = $aKeyedFields[$iKey]; unset($aKeyedFields[$iKey]); } // add children to stack $aStack = kt_array_merge($aStack, $aOrders[$iKey]); } $this->oPage->setBreadcrumbDetails(_kt('Manage complex conditional')); $aTemplateData = array("context" => &$this, "fieldset_id" => $fieldset_id, "ordering" => $aOrders, "aFields" => $aOrderedFields, "iMasterFieldId" => $oFieldset->getMasterFieldId()); return $oTemplate->render($aTemplateData); }
function do_viewCategory() { // are we categorised, or not? $category = KTUtil::arrayGet($_REQUEST, 'fCategory', $this->category); $oRegistry =& KTAdminNavigationRegistry::getSingleton(); $aCategory = $oRegistry->getCategory($category); $aItems = $oRegistry->getItemsForCategory($category); asort($aItems); $this->aBreadcrumbs[] = array('name' => $aCategory['title'], 'url' => KTUtil::ktLink('admin.php', $category)); $this->oPage->title = _kt('DMS Administration') . ': ' . $aCategory['title']; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('kt3/admin_items'); $aTemplateData = array('context' => $this, 'category' => $aCategory, 'items' => $aItems, 'baseurl' => $_SERVER['PHP_SELF']); return $oTemplate->render($aTemplateData); }
function delete($oDocument, $sReason, $iDestFolderId = null) { // use the deleteSymbolicLink function is this is a symlink if ($oDocument->isSymbolicLink()) { return KTDocumentUtil::deleteSymbolicLink($oDocument); } $oDocument =& KTUtil::getObject('Document', $oDocument); if (is_null($iDestFolderId)) { $iDestFolderId = $oDocument->getFolderID(); } $oStorageManager =& KTStorageManagerUtil::getSingleton(); global $default; if (count(trim($sReason)) == 0) { return PEAR::raiseError(_kt('Deletion requires a reason')); } if (PEAR::isError($oDocument) || $oDocument == false) { return PEAR::raiseError(_kt('Invalid document object.')); } if ($oDocument->getIsCheckedOut() == true) { return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName())); } if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.delete')) { return PEAR::raiseError(_kt('Document cannot be deleted as it is restricted by the workflow.')); } // IF we're deleted ... if ($oDocument->getStatusID() == DELETED) { return true; } $oOrigFolder = Folder::get($oDocument->getFolderId()); DBUtil::startTransaction(); // flip the status id $oDocument->setStatusID(DELETED); // $iDestFolderId is DEPRECATED. $oDocument->setFolderID(null); $oDocument->setRestoreFolderId($oOrigFolder->getId()); $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId())); $res = $oDocument->update(); if (PEAR::isError($res) || $res == false) { DBUtil::rollback(); return PEAR::raiseError(_kt('There was a problem deleting the document from the database.')); } // now move the document to the delete folder $res = $oStorageManager->delete($oDocument); if (PEAR::isError($res) || $res == false) { //could not delete the document from the file system $default->log->error('Deletion: Filesystem error deleting document ' . $oDocument->getFileName() . ' from folder ' . Folder::getFolderPath($oDocument->getFolderID()) . ' id=' . $oDocument->getFolderID()); // we use a _real_ transaction here ... DBUtil::rollback(); /* //reverse the document deletion $oDocument->setStatusID(LIVE); $oDocument->update(); */ return PEAR::raiseError(_kt('There was a problem deleting the document from storage.')); } // get the user object $oUser = User::get($_SESSION['userID']); //delete all shortcuts linking to this document $aSymlinks = $oDocument->getSymbolicLinks(); foreach ($aSymlinks as $aSymlink) { $oShortcutDocument = Document::get($aSymlink['id']); $oOwnerUser = User::get($oShortcutDocument->getOwnerID()); KTDocumentUtil::deleteSymbolicLink($aSymlink['id']); //send an email to the owner of the shortcut if ($oOwnerUser->getEmail() != null && $oOwnerUser->getEmailNotification() == true) { $emailTemplate = new EmailTemplate("kt3/notifications/notification.SymbolicLinkDeleted", array('user_name' => $oUser->getName(), 'url' => KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)), 'title' => $oShortcutDocument->getName())); $email = new EmailAlert($oOwnerUser->getEmail(), _kt("KnowledgeTree Notification"), $emailTemplate->getBody()); $email->send(); } } $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete'); $oDocumentTransaction->create(); $oDocument->setFolderID(1); DBUtil::commit(); // we weren't doing notifications on this one $oSubscriptionEvent = new SubscriptionEvent(); $oSubscriptionEvent->RemoveDocument($oDocument, $oOrigFolder); // document is now deleted: triggers are best-effort. $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('delete', '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)) { $oDocument->delete(); // FIXME nbm: review that on-fail => delete is correct ?! return $ret; } } }
function notify_restore() { $iDocId = $this->oNotification->getIntData1(); $res = $this->restore($iDocId); if (PEAR::isError($res) || !$res) { $msg = _kt('Document could not be restored'); if ($res) { $msg .= ': ' . $res->getMessage(); } $this->addErrorMessage($msg); } else { $this->addInfoMessage(_kt('The document has been successfully restored.')); } $notify_id = $_REQUEST['id']; $url = KTUtil::ktLink("notify.php", '', "id={$notify_id}"); exit(redirect($url)); }